I have the code below, and when it gets to the DT = DS.Tables(0) after the DA.Fill(DS) it jumps into the exception. Can anyone tell me why this is happening?
What i am trying to do is retrive the ID assigned to the record that has been inserted by SQL1
I have checked, and the records are being inserted into the database as well
vb Code:
If Me.cmb_client.Visible = True Then client = Me.cmb_client.SelectedValue Else ' INSERT into the client table for new record Conn.Open() Comm = New System.Data.OleDb.OleDbCommand(SQL1, Conn) MessageBox.Show(SQL1) Comm.ExecuteNonQuery() Comm.Dispose() 'retrieve client id Comm = New System.Data.OleDb.OleDbCommand(sqlcliret, Conn) 'defines new data adapter Dim DA As New System.Data.OleDb.OleDbDataAdapter DA.SelectCommand = Comm ' defines new dataset Dim DS As New DataSet Try DA.Fill(DS) DT = DS.Tables(0) Catch ex As Exception 'The user may have entered a string as their login id MessageBox.Show(Err.Description) Me.Close() Exit Sub End Try Comm.Dispose() DA.Dispose() 'if the number of rows returned = 0 displays message to the user If DT.Rows.Count = 0 Then MessageBox.Show("No records match your search" & vbNewLine & "Please try different criteria", "Search Results", MessageBoxButtons.OK, MessageBoxIcon.Information) Me.Close() Exit Sub Else RecordNo = 0 suspectID = DT.Rows(RecordNo).Item("Suspect_Name").ToString MessageBox.Show(suspectID) End If 'set client id 'client = new value End If




Reply With Quote