Updating the database from a datagridview

mahmood

Member
Joined
Feb 5, 2007
Messages
20
Programming Experience
Beginner
I have a datagridview which gets its data from a datasource. I have tried a lot of places to find out how I can easily update the rows back to the database but to no use. This is what I have so far:
Conn.ConnectionString = ConnString
Comm.CommandText = SqlString
Comm.Connection = Conn
Conn.Open()

oDa.SelectCommand = Comm
oDa.Fill(oDs, "Directory")

dgvDirs.DataSource = oDs.Tables("Directory")

Now I have a button and I want to update the database upon clicking this button. This is what I have so far inside the click event:
oDa.UpdateCommand = New OleDbCommand("UPDATE Directory SET D_SUBIT_PAGE=@D_SUBMIT_PAGE WHERE D_ID=@D_ID", Conn)
oDa.Update()

But it doesn't work.

What lines of code do I put inside the click event for this to work?
 
Try using a commandbuilder..Try this:
VB.NET:
 Dim oCmb As OleDb.OleDbCommandBuilder(oDa)
oDa.Fill(oDs,"Directory")
 
Back
Top