Kaskus

Tech

fhariezAvatar border
TS
fhariez
executereader connection property has not been initialized
Agan master programmer, mohon bantuannya donk ada yang salah sama coding ane dibawah?

Imports System.Data.OleDb

Public Class Form1
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
Dim DB As OleDb.OleDbConnection
Dim Dc As New OleDb.OleDbCommand()
Dim Da As New OleDb.OleDbDataAdapter()
Dim RS As OleDbDataReader
Dim Ds As New DataSet()
Dim TotalC As Long
Dim sql As String
Dim sqlquery As OleDb.OleDbCommand
Dim database As OleDb.OleDbConnection

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Disable(Me)
Call namabarge()
End Sub

Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)
Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), &HF060, 1)
Case &HFFFFFFFF
End Select
End Sub

Private Sub Connect()
Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\DBMaster.accdb"
Try
DB = New OleDbConnection("Provider=microsoft.ace.oledb.12.0; data source='" & STrPath & "'")
Dc = New OleDbCommand("Select * from Loading order by MuatanAwal asc")
DB.Open()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "")
End
End Try
Dc.Connection = DB
Da = New OleDb.OleDbDataAdapter("Select * from Loading order by MuatanAwal asc", DB)
Ds = New DataSet("Loading")
Da.Fill(Ds, "Loading")
DataGridView2.DataSource = Ds
DataGridView2.DataMember = "Loading"
Dim x = Ds.Tables("Loading").Rows.Count()
TotalC = x - 1
FILL(0)
DB.Close()
NormalBUtton()
End Sub

Private Sub Connect1()
Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\DBMaster.accdb"
Try
DB = New OleDbConnection("Provider=microsoft.ace.oledb.12.0; data source='" & STrPath & "'")
Dc = New OleDbCommand("Select * from HASIL")
DB.Open()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "")
End
End Try
Dc.Connection = DB
Da = New OleDb.OleDbDataAdapter("Select * from HASIL", DB)
Ds = New DataSet("HASIL")
Da.Fill(Ds, "HASIL")
DataGridView1.DataSource = Ds
DataGridView1.DataMember = "HASIL"
Dim x = Ds.Tables("HASIL").Rows.Count()
TotalC = x - 1
FILL(0)
DB.Close()
NormalBUtton()
End Sub

Private Sub UPDATE1()
DB.Open()
Dim SQL As String
SQL = "Update Loading set MuatanAwal='" & tcargoawal1.Text & "', Jam='" & tjloading1.Text & "', Tanggal='" & twloading1.Text & "', " _
& "Productivity='" & tpdty1.Text & "'"
'MsgBox(SQL)
Dim Ct As New OleDbCommand(SQL, DB)
Ct.ExecuteNonQuery()
DB.Close()
Connect()
End Sub

Private Sub ConnectBarge()
Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\DBMaster.accdb"
Try
DB = New OleDbConnection("Provider=microsoft.ace.oledb.12.0; data source='" & STrPath & "'")
Dc = New OleDbCommand("Select * from BARGE order by NamaBarge asc")
DB.Open()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "")
End
End Try
Dc.Connection = DB
Da = New OleDb.OleDbDataAdapter("Select * from BARGE order by NamaBarge asc", DB)
Ds = New DataSet("BARGE")
Da.Fill(Ds, "BARGE")
DataGridView3.DataSource = Ds
DataGridView3.DataMember = "BARGE"
Dim x = Ds.Tables("BARGE").Rows.Count()
TotalC = x - 1
FILL(0)
DB.Close()
NormalBUtton()
End Sub

Private Sub UPDATEBarge()
DB.Open()
Dim SQL As String
SQL = "Update BARGE set NamaBarge='" & tnamabarge1.Text & "', MD='" & a.Text & "', TPC='" & ttpc.Text & "', " _
& "COB='" & tcob.Text & "', LOA='" & tdimensi.Text & "'"
'MsgBox(SQL)
Dim Ct As New OleDbCommand(SQL, DB)
Ct.ExecuteNonQuery()
DB.Close()
Connect()
End Sub

Private Sub FILL(ByVal X As Long)
If Ds Is Nothing Then Return
Try
With Ds.Tables("Loading").Rows(X)
tcargoawal1.Text = IIf(IsDBNull(.Item("MuatanAwal")), "NULL", .Item("MuatanAwal"))
twloading1.Text = IIf(IsDBNull(.Item("Tanggal")), "NULL", .Item("Tanggal"))
tjloading1.Text = IIf(IsDBNull(.Item("Jam")), "NULL", .Item("Jam"))
tpdty1.Text = IIf(IsDBNull(.Item("Productivity")), "NULL", .Item("Productivity"))
End With
Catch err As Exception
End Try
Try
With Ds.Tables("BARGE").Rows(X)
tnamabarge1.Text = IIf(IsDBNull(.Item("NamaBarge")), "NULL", .Item("NamaBarge"))
a.Text = IIf(IsDBNull(.Item("MD")), "NULL", .Item("MD"))
ttpc.Text = IIf(IsDBNull(.Item("TPC")), "NULL", .Item("TPC"))
tcob.Text = IIf(IsDBNull(.Item("COB")), "NULL", .Item("COB"))
tdimensi.Text = IIf(IsDBNull(.Item("LOA")), "NULL", .Item("LOA"))
End With
Catch err As Exception
End Try
Me.Text = X
End Sub

Private Sub CLEAR()
Me.tcargoawal1.Text = ""
Me.twloading1.Text = ""
Me.tjloading1.Text = ""
Me.tpdty1.Text = ""
Me.ccaribarge.Text = ""
End Sub

Private Sub EnabledButton()
bproses.Enabled = True
End Sub

Private Sub NormalBUtton()
bproses.Enabled = False
End Sub

Private Sub SAVE()
Dim DC1 As New OleDb.OleDbCommand()
Dim SQL As String
DB.Open()
SQL = "Insert into Loading(MuatanAwal,Tanggal,Productivity,Jam) values(" _
& "'" & tcargoawal1.Text & "', " _
& "'" & twloading1.Text & "', " _
& "'" & tpdty1.Text & "', " _
& "'" & tjloading1.Text & "')"
'MsgBox(SQL)
'SQL = "Insert into sc(name) values('x')"
DC1 = New OleDbCommand(SQL, DB)
DC1.ExecuteNonQuery()
' MsgBox("Save", MsgBoxStyle.OKOnly, "")
DB.Close()
Connect()
End Sub

Private Sub IsikankeDatabase()
If ccaribarge.Text = "" Then
MsgBox("Nama Barge tidak boleh kosong!", MsgBoxStyle.Information, "")
ccaribarge.Focus()
ElseIf tcargoawal1.Text = "" Then
MsgBox("Muatan awal tidak boleh kosong!", MsgBoxStyle.Information, "")
tcargoawal1.Focus()
ElseIf tpdty1.Text = "" Then
MsgBox("Productivity tidak boleh kosong!", MsgBoxStyle.Information, "")
tpdty1.Focus()
ElseIf twloading1.Text = "" Then
MsgBox("Tanggal Loading tidak boleh kosong!", MsgBoxStyle.Information, "")
twloading1.Focus()
ElseIf tjloading1.Text = "" Then
MsgBox("Jam Loading tidak boleh kosong!", MsgBoxStyle.Information, "")
tjloading1.Focus()
Else
Call UPDATE1()
End If
End Sub

Private Sub EDIT()
EnabledButton()
End Sub

Private Sub bproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bproses.Click
IsikankeDatabase()
End Sub

Private Sub Binding_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Connect()
Connect1()
ConnectBarge()
UPDATEBarge()
End Sub

Private Sub tcargoawal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tcargoawal1.KeyPress
EDIT()
End Sub

Private Sub twloading_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles twloading1.KeyPress
EDIT()
End Sub

Private Sub tjloading_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tjloading1.KeyPress
EDIT()
End Sub

Private Sub bbersihkan_Click(sender As Object, e As EventArgs) Handles bbersihkan.Click
Call CLEAR()
End Sub

Private Sub bkeluar_Click(sender As Object, e As EventArgs) Handles bkeluar.Click
End
End Sub

Private Sub binput2_Click(sender As Object, e As EventArgs) Handles binput2.Click
Me.Hide()
Form2.Show()
End Sub

Public Sub OpenDB()
Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\DBMaster.accdb"
DB = New OleDbConnection("Provider=microsoft.ace.oledb.12.0; data source='" & STrPath & "'")
If DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub

Private Sub namabarge()
Call OpenDB()
sql = "SELECT * FROM DataBarge"
Dc = New OleDbCommand(sql, DB)
RS = Dc.ExecuteReader
ccaribarge.Items.Clear()
Do While RS.Read()
ccaribarge.Items.Add(RS("NamaBarge"))
Loop
DB.Close()
End Sub

Private Sub pilih_MD()
sql = "SELECT MD FROM DataBarge WHERE NamaBarge='" & Me.ccaribarge.SelectedItem & "'"
sqlquery = New OleDb.OleDbCommand(sql, database)
RS = sqlquery.ExecuteReader
RS.Read()
Me.tmd.Text = RS("MD")
DB.Close()
End Sub

Private Sub ccaribarge_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ccaribarge.SelectedIndexChanged
pilih_MD()
End Sub

Private Sub tcargoawal1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tcargoawal1.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
If Not (((tombol >= 48) And (tombol <= 57)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub

Private Sub tpdty1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tpdty1.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
If Not (((tombol >= 48) And (tombol <= 57)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
End Class

penampakannya kaya gini gan :
executereader connection property has not been initialized

Mohon pencerahannya agan master sekalian....emoticon-Sorryemoticon-Sorry
0
965
0
GuestAvatar border
Komentar yang asik ya
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan