Friends,
I am a beginner to VB.net programming and Im trying some DB application. Using Visual Studio 2008 and MS Access 2003 . The following code is filling dataset correctly, but fails to add the newly added row to database. There is no error/exception. Could you please help in getting this corrected?
Dim connection As OleDbConnection
Dim adaptor As OleDbDataAdapter
Dim dset As DataSet
Dim cb As OleDbCommandBuilder
dset = New DataSet()
connection = New OleDbConnection(ConnectionString)
adaptor = New OleDbDataAdapter()
adaptor.SelectCommand = New OleDbCommand(GetAllPatients, connection)
cb = New OleDbCommandBuilder(adaptor)
connection.Open()
adaptor.Fill(dset, "Patients")
' add new row to dataset
Console.WriteLine(dset.Tables(0).Rows.Count.ToString)
Dim table As DataTable = dset.Tables("Patients")
Dim row As DataRow = table.NewRow()
row("PatientID") = Convert.ToString((dset.Tables(0).Rows.Count + 1))
row("FirstName") = TxtFirstName.Text
Row("Surname") = TxtSurname.Text
Row("Age") = Txtage.Text
If RbtMale.Checked = True Then
Row("Gender") = "Male"
ElseIf Rbtfemale.Checked = True Then
Row("Gender") = "Female"
End If
Row("HouseName") = TxtHouseName.Text
Row("Street") = TxtStreet.Text
Row("Post") = TxtPost.Text
Row("Place") = Txtplace.Text
Row("District") = TxtDistrict.Text
Row("State") = TxtState.Text
Row("PinCode") = TxtPinCode.Text
Row("Phone1") = TxtPhone.Text
Row("Phone2") = TxtAltPhone.Text
Row("Mobile") = TxtMobile.Text
Row("Email1") = TxtEmail.Text
Row("Email2") = TxtAltEmail.Text
Row("DateOfEntry") = Now.Date
Row("Notes") = Rtbnotes.Text
dset.Tables(0).Rows.Add(row)
Console.WriteLine(dset.Tables(0).Rows.Count.ToString)
adaptor.Update(dset, "Patients")
dset.AcceptChanges()
connection.Close()
I am a beginner to VB.net programming and Im trying some DB application. Using Visual Studio 2008 and MS Access 2003 . The following code is filling dataset correctly, but fails to add the newly added row to database. There is no error/exception. Could you please help in getting this corrected?
Dim connection As OleDbConnection
Dim adaptor As OleDbDataAdapter
Dim dset As DataSet
Dim cb As OleDbCommandBuilder
dset = New DataSet()
connection = New OleDbConnection(ConnectionString)
adaptor = New OleDbDataAdapter()
adaptor.SelectCommand = New OleDbCommand(GetAllPatients, connection)
cb = New OleDbCommandBuilder(adaptor)
connection.Open()
adaptor.Fill(dset, "Patients")
' add new row to dataset
Console.WriteLine(dset.Tables(0).Rows.Count.ToString)
Dim table As DataTable = dset.Tables("Patients")
Dim row As DataRow = table.NewRow()
row("PatientID") = Convert.ToString((dset.Tables(0).Rows.Count + 1))
row("FirstName") = TxtFirstName.Text
Row("Surname") = TxtSurname.Text
Row("Age") = Txtage.Text
If RbtMale.Checked = True Then
Row("Gender") = "Male"
ElseIf Rbtfemale.Checked = True Then
Row("Gender") = "Female"
End If
Row("HouseName") = TxtHouseName.Text
Row("Street") = TxtStreet.Text
Row("Post") = TxtPost.Text
Row("Place") = Txtplace.Text
Row("District") = TxtDistrict.Text
Row("State") = TxtState.Text
Row("PinCode") = TxtPinCode.Text
Row("Phone1") = TxtPhone.Text
Row("Phone2") = TxtAltPhone.Text
Row("Mobile") = TxtMobile.Text
Row("Email1") = TxtEmail.Text
Row("Email2") = TxtAltEmail.Text
Row("DateOfEntry") = Now.Date
Row("Notes") = Rtbnotes.Text
dset.Tables(0).Rows.Add(row)
Console.WriteLine(dset.Tables(0).Rows.Count.ToString)
adaptor.Update(dset, "Patients")
dset.AcceptChanges()
connection.Close()