Update Data in a Datagrid
-
I am having difficulty getting the underlying SQL data to update when a change is made to the datagrid. The change is made using a combobox, and allows the proper selection of 1 of the 3 choices, but I can't seem to get the syntax/code right to update the table. Here is my current code: Public Sub comboControl_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles comboControl.SelectedValueChanged grdVW_AllOpen(hitTestGrid.Row, hitTestGrid.Column) = comboControl.Text Dim sc1 As New SqlCommand Dim sCnnStr As String sCnnStr = "Data Source=" & SQL_SERVER & ";Initial Catalog=" & DATABASE & ";User id=" & USER_ID & ";Password=" & PWD Dim sqlConn As New SqlConnection(sCnnStr) sc1.Connection = sqlConn sc1.CommandType = CommandType.Text sc1.CommandText = "UPDATE dbo.Chits_Backup SET Status = '" & comboControl.Text & "'" & ", LastName = @LastName, FirstName = @FirstName, DateofRequest = @DateofRequest, FromDate = @FromDate, ToDate = @ToDate, Days = @Days, NatureofRequest = @NatureofRequest WHERE ID = @ID" Dim cmd As New SqlClient.SqlCommand(sc1.CommandText) 'Create the sql command object and set its command type to execute the sql query to get the results sc1.Parameters.Add("@Status", SqlDbType.NVarChar, 50, "Status").Value = comboControl.Text sc1.Parameters.Add("@LastName", SqlDbType.NVarChar, 50, "LastName").Value = "@LastName" sc1.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50, "FirstName").Value = "@FirstName" sc1.Parameters.Add("@DateofRequest", SqlDbType.NVarChar, 50, "DateofRequest").Value = "@DateofRequest" sc1.Parameters.Add("@FromDate", SqlDbType.DateTime, 8, "FromDate").Value = "@FromDate" sc1.Parameters.Add("@ToDate", SqlDbType.DateTime, 8, "ToDate").Value = "@ToDate" sc1.Parameters.Add("@Days", SqlDbType.NVarChar, 50, "Days").Value = "@Days" sc1.Parameters.Add("@NatureofRequest", SqlDbType.NVarChar, 50, "NatureofRequest").Value = "@NatureofRequest" Dim myParm2 As SqlParameter = sc1.Parameters.Add("@ID", SqlDbType.Int, 4, "ID") myParm2.SourceVersion = DataRowVersion.Original sqlConn.Open() Try sc1.ExecuteNonQuery() Catch ex As SqlException MsgBox(ex.Message().ToString()) End Try sqlConn.Close() I know it has to do with the handling of variables, but can't narrow it down. Thank you, LWhite:)