kcwallace
Centurion
Is there a tutorial that will show me how to bind a DataGridView to a dataset that is linked to a database, and successfully update the records. I cannot seem to figure out how to make a UpdateCommand work successfully. I am using VS 2005 and VB.Net
THe code below is my attempt. I am unsure how to actually force an update
THe code below is my attempt. I am unsure how to actually force an update
Visual Basic:
Public Class EmulsionAgeData
Private Cnn As New SqlConnection(myconnectionstring)
Private Cmd As New SqlCommand
Private DS As New DataSet
Private DA As New SqlDataAdapter
Private UCmd As New SqlCommand
Private Sub EmulsionAgeData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Cmd
.Connection = Cnn
.CommandType = CommandType.Text
.CommandText = "SELECT * FROM EmulsionData ORDER BY EmulID"
End With
Cnn.Open()
DA.SelectCommand = Cmd
DA.Fill(DS)
DataGridView1.DataSource = DS
DataGridView1.DataMember = DS.Tables(0).TableName
UCmd.CommandText = "UPDATE EmulsionData SET EmulID=@Emul, StartDate=@Sdate, StartOD=@SOD WHERE EmulID=@Emul"
UCmd.Connection = Cnn
UCmd.CommandType = CommandType.Text
UCmd.Parameters.Add("@Emul", SqlDbType.NVarChar, 3)
UCmd.Parameters.Add("@SDate", SqlDbType.DateTime)
UCmd.Parameters.Add("@SOD", SqlDbType.Float)
DA.UpdateCommand = UCmd
End Sub
End Class