esmyhs
asked on
MissingPrimaryKeyException Error while Searching an Access Table in VB2008
I'm new to VB2008 and ADO.NET. I've been using VB6 with DAO extensively and have just started to upgrade to VB2008.
I'm using the following code to try to search for a Value in an Access table. The field that I am trying to search is called "ID".
Dim foundRow As DataRow
Dim findThis As Object
findThis = 21844
foundRow = objDataSet.Tables(0).Rows. Find(findT his)
I'm getting the following error message on the last line, even though the ID field is set in the table as a Primary Key field:
System.Data.MissingPrimary KeyExcepti on was unhandled
Message="Table doesn't have a primary key."
Any help would be appreciated. Thanks.
I'm using the following code to try to search for a Value in an Access table. The field that I am trying to search is called "ID".
Dim foundRow As DataRow
Dim findThis As Object
findThis = 21844
foundRow = objDataSet.Tables(0).Rows.
I'm getting the following error message on the last line, even though the ID field is set in the table as a Primary Key field:
System.Data.MissingPrimary
Message="Table doesn't have a primary key."
Any help would be appreciated. Thanks.
and was your ID field was retreived in your dataset? can you show the code that fills your dataset?
ASKER
Dim objConnection As New OleDbConnection _
("Provider=Microsoft.Jet.O LEDB.4.0;D ata source=C:\CSBView\View.MDB ")
Dim objDataAdapter As New OleDbDataAdapter _
("SELECT Nikud.ID, Nikud.text FROM Nikud ORDER BY Nikud.ID", _
objConnection)
'Initialize a new instance of the DataSet object...
objDataSet = New DataSet
'Fill the DataSet object with data...
objDataAdapter.Fill(objDat aSet, "Nikud")
'Set the DataView object to the DataSet object...
objDataView = New DataView(objDataSet.Tables ("Nikud"))
("Provider=Microsoft.Jet.O
Dim objDataAdapter As New OleDbDataAdapter _
("SELECT Nikud.ID, Nikud.text FROM Nikud ORDER BY Nikud.ID", _
objConnection)
'Initialize a new instance of the DataSet object...
objDataSet = New DataSet
'Fill the DataSet object with data...
objDataAdapter.Fill(objDat
'Set the DataView object to the DataSet object...
objDataView = New DataView(objDataSet.Tables
Hi,
Another approach is to use the RowFilter property of the DataView associate with DataTable.
Here is an example.
objDataSet.Tables(0).Defau ltView.Row Filter="ID =" & txtID.text
if objDataSet.Tables(0).Defau ltView.Cou nt >0 then
messagebox.show(objDataSet .Tables(0) .DefaultVi ew.item(0) .item("Tex t"))
end if
Another approach is to use the RowFilter property of the DataView associate with DataTable.
Here is an example.
objDataSet.Tables(0).Defau
if objDataSet.Tables(0).Defau
messagebox.show(objDataSet
end if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. Greatly appreciated.