G
Guest
if I have a simple Access table like so:
Customer = (customerNo , firstName, lastName)
and the customerNo field has autonumbering set (i.e. is the primary key
value in the table and is a number that increments automatically when a new
record is added).
When I extract all records using a Dataset object. I want to add return the
value of the customerNo if I were to add a new record. So if I added a new
customer to the table I want to return a new customer number.
Do you know to do this >>!!? can the following code be adpated to do this
!?!??!
Public Function getData() As DataSet
Const INT_EMPTY As Integer = 0
Try
If mblnIsDatabaseOpen Then
Dim pstrSQL As String
If sqltext = "" Then Exit Function
Dim pobjAdtAdaptor As New OleDbDataAdapter
Dim pobjdstDataset As New DataSet
Dim sqlText = "SELECT * FOM CUSTOMER;"
pobjAdtAdaptor.SelectCommand = New OleDbCommand(sqltext,
mcnnObjConnection)
pobjdstDataset.Clear()
If pobjAdtAdaptor.Fill(pobjdstDataset, "Data") = INT_EMPTY
Then
getData = Nothing
Else
getData = pobjdstDataset.Tables("Data").DataSet
End If
pobjAdtAdaptor = Nothing
pobjdstDataset = Nothing
Else
MsgBox("Database not open")
End If
Catch ex As Exception
MsgBox("Could not query the database", MsgBoxStyle.Critical)
If mblnIsDatabaseOpen Then closeDatabase()
Exit Function
End Try
End Function
Customer = (customerNo , firstName, lastName)
and the customerNo field has autonumbering set (i.e. is the primary key
value in the table and is a number that increments automatically when a new
record is added).
When I extract all records using a Dataset object. I want to add return the
value of the customerNo if I were to add a new record. So if I added a new
customer to the table I want to return a new customer number.
Do you know to do this >>!!? can the following code be adpated to do this
!?!??!
Public Function getData() As DataSet
Const INT_EMPTY As Integer = 0
Try
If mblnIsDatabaseOpen Then
Dim pstrSQL As String
If sqltext = "" Then Exit Function
Dim pobjAdtAdaptor As New OleDbDataAdapter
Dim pobjdstDataset As New DataSet
Dim sqlText = "SELECT * FOM CUSTOMER;"
pobjAdtAdaptor.SelectCommand = New OleDbCommand(sqltext,
mcnnObjConnection)
pobjdstDataset.Clear()
If pobjAdtAdaptor.Fill(pobjdstDataset, "Data") = INT_EMPTY
Then
getData = Nothing
Else
getData = pobjdstDataset.Tables("Data").DataSet
End If
pobjAdtAdaptor = Nothing
pobjdstDataset = Nothing
Else
MsgBox("Database not open")
End If
Catch ex As Exception
MsgBox("Could not query the database", MsgBoxStyle.Critical)
If mblnIsDatabaseOpen Then closeDatabase()
Exit Function
End Try
End Function