VB.NET and Access 2002

  • Thread starter Thread starter Tom H
  • Start date Start date
T

Tom H

Hi, I am creating a GUI for my access database in VB.NET. I have created
the Data connection, DataAdapter, DataSet and CommandBuilder in code.
The program connects and reads data. When I use a find to get the
current record I get an exception stating that my table has no primary
key. I have defined the yourID column as unique and primary key. I am
not sure why VB doesn't understand that a primary key exists. Any Ideas?

Revelent Code ... (don't laugh I'm new at this =) )

Public Class Form1

Inherits System.Windows.Forms.Form
Dim frmEnterPay As New Form2b()

'database connection code
Dim objConnection As New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=judgment.mdb")
Dim objJudgmentinfoDA As New OleDb.OleDbDataAdapter("Select * from
judgmentinfo", objConnection)
Dim objJudgmentinfoCB As New
OleDb.OleDbCommandBuilder(objJudgmentinfoDA)
Dim objDataSet As New DataSet()



Public Sub fillDS()
'clear dataset
objDataSet.Clear()
'fill schema
objJudgmentinfoDA.FillSchema(objDataSet, SchemaType.Source,
"judgmetninfo")
'fill dataset from judgmentinfo table
objJudgmentinfoDA.Fill(objDataSet, "judgmentinfo")
'clear combo box
cboDbtr.Items.Clear()

'loop through each row, adding the debtors ID to the combo box
Dim i As Integer, strCurrentID As String
For i = 1 To objDataSet.Tables("judgmentinfo").Rows.Count
strCurrentID = objDataSet.Tables("judgmentinfo").Rows(i -
1).Item("yourID")
cboDbtr.Items.Add(strCurrentID)
Next
'select first item on the list
cboDbtr.SelectedIndex = 0



End Sub
Public Sub FillDetails()
Dim objRow As DataRow

'throws exception on next line****

objRow =
objDataSet.Tables("judgmentinfo").Rows.Find(cboDbtr.SelectedItem.ToStrin
g)
txtCdtName.Text = objRow.Item("lname")
txtCdtLName.Text = objRow.Item("fname")
 
¤ Hi, I am creating a GUI for my access database in VB.NET. I have created
¤ the Data connection, DataAdapter, DataSet and CommandBuilder in code.
¤ The program connects and reads data. When I use a find to get the
¤ current record I get an exception stating that my table has no primary
¤ key. I have defined the yourID column as unique and primary key. I am
¤ not sure why VB doesn't understand that a primary key exists. Any Ideas?
¤
¤ Revelent Code ... (don't laugh I'm new at this =) )
¤
¤ Public Class Form1
¤
¤ Inherits System.Windows.Forms.Form
¤ Dim frmEnterPay As New Form2b()
¤
¤ 'database connection code
¤ Dim objConnection As New
¤ OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
¤ Source=judgment.mdb")
¤ Dim objJudgmentinfoDA As New OleDb.OleDbDataAdapter("Select * from
¤ judgmentinfo", objConnection)
¤ Dim objJudgmentinfoCB As New
¤ OleDb.OleDbCommandBuilder(objJudgmentinfoDA)
¤ Dim objDataSet As New DataSet()
¤ …
¤
¤
¤ Public Sub fillDS()
¤ 'clear dataset
¤ objDataSet.Clear()
¤ 'fill schema
¤ objJudgmentinfoDA.FillSchema(objDataSet, SchemaType.Source,
¤ "judgmetninfo")
¤ 'fill dataset from judgmentinfo table
¤ objJudgmentinfoDA.Fill(objDataSet, "judgmentinfo")
¤ 'clear combo box
¤ cboDbtr.Items.Clear()
¤
¤ 'loop through each row, adding the debtors ID to the combo box
¤ Dim i As Integer, strCurrentID As String
¤ For i = 1 To objDataSet.Tables("judgmentinfo").Rows.Count
¤ strCurrentID = objDataSet.Tables("judgmentinfo").Rows(i -
¤ 1).Item("yourID")
¤ cboDbtr.Items.Add(strCurrentID)
¤ Next
¤ 'select first item on the list
¤ cboDbtr.SelectedIndex = 0
¤
¤
¤
¤ End Sub
¤ Public Sub FillDetails()
¤ Dim objRow As DataRow
¤
¤ 'throws exception on next line****
¤
¤ objRow =
¤ objDataSet.Tables("judgmentinfo").Rows.Find(cboDbtr.SelectedItem.ToStrin
¤ g)
¤ txtCdtName.Text = objRow.Item("lname")
¤ txtCdtLName.Text = objRow.Item("fname")
¤

Try changing the SchemaType in the FillSchema method to Mapped (instead of Source).


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top