EDN Admin
Well-known member
Hello all!
I try to update a sql db table with 4 columns binding to datagridview. I have loop the datagridview in order to compare tha values and l have give some new values to the 4th column of the datagridview (Error messages like min,max etc). What i need
to do now is to save these changes and update the sql table. The query I created:
<pre class="prettyprint lang-vb For i = 0 To T_AMR_WaterMeterReadingsDataGridView.Rows.Count - 1
Try
Dim conn As New System.Data.SqlClient.SqlConnection(ConnectionString)
cmd.CommandType = System.Data.CommandType.Text
Dim dt As DateTime
Dim date1 As String
date1 = Convert.ToString(T_AMR_WaterMeterReadingsDataGridView.Rows(i).Cells(2).Value)
dt = Convert.ToDateTime(date1)
cmd.CommandText = ("set dateformat DMY UPDATE T_AMR_WaterMeterReadings set AMR_Warning=" & T_AMR_WaterMeterReadingsDataGridView.Rows(i).Cells(4).Value & " where AMR_SerialNumber=" & T_AMR_WaterMeterReadingsDataGridView.Rows(i).Cells(0).Value & " and AMR_DateTime=" & date1 & "")
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
MsgBox("", vbInformation, "")
Catch ex1 As Exception
MessageBox.Show("Error while inserting record on table..." & ex1.Message, "")
Finally
End Try
Next[/code]
<br/>
But the problem is that there is conversion error about the datetime "Conversion failed when converting datetime from character string"
Pls help is urgent!
View the full article
I try to update a sql db table with 4 columns binding to datagridview. I have loop the datagridview in order to compare tha values and l have give some new values to the 4th column of the datagridview (Error messages like min,max etc). What i need
to do now is to save these changes and update the sql table. The query I created:
<pre class="prettyprint lang-vb For i = 0 To T_AMR_WaterMeterReadingsDataGridView.Rows.Count - 1
Try
Dim conn As New System.Data.SqlClient.SqlConnection(ConnectionString)
cmd.CommandType = System.Data.CommandType.Text
Dim dt As DateTime
Dim date1 As String
date1 = Convert.ToString(T_AMR_WaterMeterReadingsDataGridView.Rows(i).Cells(2).Value)
dt = Convert.ToDateTime(date1)
cmd.CommandText = ("set dateformat DMY UPDATE T_AMR_WaterMeterReadings set AMR_Warning=" & T_AMR_WaterMeterReadingsDataGridView.Rows(i).Cells(4).Value & " where AMR_SerialNumber=" & T_AMR_WaterMeterReadingsDataGridView.Rows(i).Cells(0).Value & " and AMR_DateTime=" & date1 & "")
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
MsgBox("", vbInformation, "")
Catch ex1 As Exception
MessageBox.Show("Error while inserting record on table..." & ex1.Message, "")
Finally
End Try
Next[/code]
<br/>
But the problem is that there is conversion error about the datetime "Conversion failed when converting datetime from character string"
Pls help is urgent!
View the full article