I am using MsAccess DB and Vb.NET 2008. This is a code to check the Database for duplicate entries but m geting an Error.
" Fill: SelectCommand.Connection property has not been initialized."
And this points to LINE NO 14. What could be the cause..? thanks in adv
Dim con As OleDbConnection
Dim cmditem As New OleDbCommand
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\PROJECTS\database.mdb")
con.Open()
cmditem.CommandText = "Select * from ITEM where ItemCode='" &
Trim(Me.TextBox1.Text) & "'"
da.SelectCommand = cmditem
da.Fill(ds, "ITEM") .........................LINE 14
dt = ds.Tables("ITEM")
If dt.Rows.Count > 0 Then
MessageBox.Show("Item Code already exist in database.
Please enter different ID.", "Error", MessageBoxButtons.OK)
Exit Sub
End If
frmItems.ITEMTableAdapter.Insert(Me.TextBox1.Text, Me.TextBox2.Text, Me.TextBox3.Text)
frmItems.ITEMTableAdapter.Fill(frmItems.SDBDataSet.ITEM)
frmItems.ITEMTableAdapter.Update(frmItems.SDBDataSet.ITEM)