Why SqlDataAdapter not update data?

Legiadinh1001

New member
Joined
Feb 20, 2008
Messages
2
Programming Experience
3-5
This is my code:

Dim tbL As New DataTable
Dim Adap As New SqlClient.SqlDataAdapter("Select * from DM_HANGHOA" ,CnnStr)
Dim cmd As New SqlClient.SqlCommandBuilder(Adap)
Adap.UpdateCommand = cmd.GetUpdateCommand
Adap.InsertCommand = cmd.GetInsertCommand
Adap.DeleteCommand = cmd.GetDeleteCommand
Adap.Fill(tbL)
Dim I As Integer
For I = 0 To tbL.Rows.Count - 1
tbL.Rows(I)("TEN") = "DLKJFDLKJF"
Next

tbL.AcceptChanges()
Adap.Update(tbL)

After Adap.Update, table DM_HANGHOA not update, please, help me!
 
Oh yuck yuck yuck.. THat's horrible data access code.

First, read the DW2 link in my signature for info on how to do it properly.. The section on Creating a Simple Data App is the best start, then read on other sections from there as you get curious.

As to why your database isnt updating, read the DNU link in my signature
 
Sorry my English not well.

That code very bad. But this problem is Adap not update to table Dm_hangHoa.
If I insert a new row or more to table tbl, Adap will insert it to table

Dim tbL As New DataTable
Dim Adap As New SqlClient.SqlDataAdapter("Select * from " & tenDM, SysDBLocal.CnnStr)
Dim cmd As New SqlClient.SqlCommandBuilder(Adap)
Adap.UpdateCommand = cmd.GetUpdateCommand
Adap.InsertCommand = cmd.GetInsertCommand
Adap.DeleteCommand = cmd.GetDeleteCommand
Adap.Fill(tbL)
Dim r As DataRow
For Each r In tbL.Rows
r("Ten") = "lđkjfljf" ' field Ten not is primary key
r.EndEdit()
Next
r = tbL.NewRow
r("Ten") = "lđjfljf"
....
....
tbL.Rows.Add(r)

tbL.AcceptChanges()
Adap.Update(tbL)
 
Back
Top