Question Update database from datagridview problem.

Kenneth Johansen

New member
Joined
Feb 17, 2012
Messages
3
Location
Tune, Denmark, Denmark
Programming Experience
1-3
Hi all,

I have a problem with updating data in the database.
When i click the button that fires the update function, it updates all but the selected row.. howcome?


Dim ds As New DataSet
Dim da As SqlDataAdapter


Sub fillGrid()

Dim sqlstr as string = "select ........"
Dim sqlcmd As New SqlCommand(sqlstr, _f.oConn)
Dim sqlcmdCount As New SqlCommand(sqlstrCount, _f.oConn)
With sqlcmd.Parameters
.Add("@Year", SqlDbType.Int).Value = CInt(Aar)
.Add("@Week", SqlDbType.Int).Value = CInt(Uge)
End With

da = New SqlDataAdapter(sqlcmd)
da.Fill(ds, "tbl_dataentry_test")
dgwData.DataSource = ds.Tables(0)

End Sub

Sub UpdateData()

Dim cmdbuilder As New SqlCommandBuilder(da)
Dim changes As DataSet = ds.GetChanges
If changes IsNot Nothing Then
Dim i As Integer
i = da.Update(ds, "tbl_dataentry_test")
MessageBox.Show("Records Updated= " & i)
End If
End Sub

 
I was perhaps a little to quick there, so just to clarify..

I'm using a datagridview to edit data, i fill the grid with the "fillGrid" sub.

When i'm done editing, i use a button to call the update sub, it the actually do update my rows, but.. no matter what row there is selected, that exact row does not get updated. I have tried a ton of things, but none of them worked...
 

Latest posts

Back
Top