Dear All, I am facing very typical problem, I am able to update record in dataset but not in database. Here is few detail about this.
I am use oldeconntion through the coding and i am able to see record in textbox and navigate farword backwork first and last. for my update button i declared one commandbuilder.
when i run the program and make few change and press update button then stop debugging. and then i run program again i am able to see changes that i was made.
but when i open ms Access data and see record they all are unchanged. How it possible to that you can see edited record in your program but data base is unalterd. one thing i want say that record chaged save in dataset but not in database. even i close whole vb 2008 and restart project and run project i am able to see change that i was made. but data base is unalterd.
Please help me in this regards with coding..
here is my code for update button.
i made msaccess conntion using jet engine thourh coding.
Private Sub updatebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updatebtn.Click
Try
Dim cmdb As New OleDbCommandBuilder(ad)
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = d:\krish.mdb"
con.Open()
sql = "SELECT * FROM Punjab"
cmdb.QuotePrefix = "["
cmdb.QuoteSuffix = "]"
ds.Tables("punjab").Rows(inc).Item(0) = TextBox1.Text
ds.Tables("punjab").Rows(inc).Item(1) = TextBox2.Text
ds.Tables("punjab").Rows(inc).Item(2) = TextBox3.Text
ds.Tables("punjab").Rows(inc).Item(3) = TextBox4.Text
ds.Tables("punjab").Rows(inc).Item(4) = TextBox5.Text
ds.Tables("punjab").Rows(inc).Item(5) = TextBox6.Text
ds.Tables("punjab").Rows(inc).Item(6) = TextBox7.Text
ds.Tables("punjab").Rows(inc).Item(7) = TextBox8.Text
ds.Tables("punjab").Rows(inc).Item(8) = TextBox9.Text
ds.Tables("punjab").Rows(inc).Item(9) = TextBox10.Text
'ds.Tables("punjab").Rows(inc).Item(10) = TextBox11.Text
cmdb.GetUpdateCommand()
ad.Fill(ds, "punjab")
ad.Update(ds, "punjab")
MsgBox("data Updated")
cmdb.RefreshSchema()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
I am use oldeconntion through the coding and i am able to see record in textbox and navigate farword backwork first and last. for my update button i declared one commandbuilder.
when i run the program and make few change and press update button then stop debugging. and then i run program again i am able to see changes that i was made.
but when i open ms Access data and see record they all are unchanged. How it possible to that you can see edited record in your program but data base is unalterd. one thing i want say that record chaged save in dataset but not in database. even i close whole vb 2008 and restart project and run project i am able to see change that i was made. but data base is unalterd.
Please help me in this regards with coding..
here is my code for update button.
i made msaccess conntion using jet engine thourh coding.
Private Sub updatebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updatebtn.Click
Try
Dim cmdb As New OleDbCommandBuilder(ad)
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = d:\krish.mdb"
con.Open()
sql = "SELECT * FROM Punjab"
cmdb.QuotePrefix = "["
cmdb.QuoteSuffix = "]"
ds.Tables("punjab").Rows(inc).Item(0) = TextBox1.Text
ds.Tables("punjab").Rows(inc).Item(1) = TextBox2.Text
ds.Tables("punjab").Rows(inc).Item(2) = TextBox3.Text
ds.Tables("punjab").Rows(inc).Item(3) = TextBox4.Text
ds.Tables("punjab").Rows(inc).Item(4) = TextBox5.Text
ds.Tables("punjab").Rows(inc).Item(5) = TextBox6.Text
ds.Tables("punjab").Rows(inc).Item(6) = TextBox7.Text
ds.Tables("punjab").Rows(inc).Item(7) = TextBox8.Text
ds.Tables("punjab").Rows(inc).Item(8) = TextBox9.Text
ds.Tables("punjab").Rows(inc).Item(9) = TextBox10.Text
'ds.Tables("punjab").Rows(inc).Item(10) = TextBox11.Text
cmdb.GetUpdateCommand()
ad.Fill(ds, "punjab")
ad.Update(ds, "punjab")
MsgBox("data Updated")
cmdb.RefreshSchema()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub