J
JFB
Hi All,
I have a edit flexgrid, after to fill with different rows manually.
How can I insert the rows of my flexgrid to my table (sql server) using
ado.net?
Any example?
I can insert one row with the code below but when I use a for loop to my
flexgrid... it doesn't work.
Also do you know any advance book for ado.net that you can recomend?
Tks in advance
JFB
Dim conn As New SqlConnection(connectionString)
'Dim insertSQL As String = "INSERT INTO
Orders(customerID,houseID,orderDate,description,employeeID,invoiceStatus)val
ues(@customerID,@houseID,@orderDate,@description,@employeeID,@invoiceStatus)
"
Dim cmd As New SqlCommand(insertSQL, conn)
Dim i As Integer
Dim Param As SqlParameter
For i = 1 To ordersFG.Rows.Count - 2
'Add the input parameters
Param = cmd.Parameters.Add("@customerID", SqlDbType.Int, 4)
Param.Value = ordersFG(i, 1)
Param = cmd.Parameters.Add("@houseID", SqlDbType.Int, 4)
Param.Value = ordersFG(i, 2)
Param = cmd.Parameters.Add("@orderDate", SqlDbType.SmallDateTime, 4)
Param.Value = ordersFG(i, 3)
Param = cmd.Parameters.Add("@employeeID", SqlDbType.Int, 4)
Param.Value = ordersFG(i, 4)
Param = cmd.Parameters.Add("@description", SqlDbType.VarChar, 255)
Param.Value = ordersFG(i, 5)
Param = cmd.Parameters.Add("@invoiceStatus", SqlDbType.Bit, 1)
Param.Value = 0
Next
Try
'Execute command
conn.Open()
Dim rows As Integer = cmd.ExecuteNonQuery
'Clear the flexgrid data
Dim rowCount
rowCount = ordersFG.Rows.Count
ordersFG.Rows.Count = ordersFG.Rows.Fixed
MsgBox("Data is already SAVE")
Catch ex As Exception
MsgBox(ex.ToString)
Return
Finally
conn.Close()
End Try
I have a edit flexgrid, after to fill with different rows manually.
How can I insert the rows of my flexgrid to my table (sql server) using
ado.net?
Any example?
I can insert one row with the code below but when I use a for loop to my
flexgrid... it doesn't work.
Also do you know any advance book for ado.net that you can recomend?
Tks in advance
JFB
Dim conn As New SqlConnection(connectionString)
'Dim insertSQL As String = "INSERT INTO
Orders(customerID,houseID,orderDate,description,employeeID,invoiceStatus)val
ues(@customerID,@houseID,@orderDate,@description,@employeeID,@invoiceStatus)
"
Dim cmd As New SqlCommand(insertSQL, conn)
Dim i As Integer
Dim Param As SqlParameter
For i = 1 To ordersFG.Rows.Count - 2
'Add the input parameters
Param = cmd.Parameters.Add("@customerID", SqlDbType.Int, 4)
Param.Value = ordersFG(i, 1)
Param = cmd.Parameters.Add("@houseID", SqlDbType.Int, 4)
Param.Value = ordersFG(i, 2)
Param = cmd.Parameters.Add("@orderDate", SqlDbType.SmallDateTime, 4)
Param.Value = ordersFG(i, 3)
Param = cmd.Parameters.Add("@employeeID", SqlDbType.Int, 4)
Param.Value = ordersFG(i, 4)
Param = cmd.Parameters.Add("@description", SqlDbType.VarChar, 255)
Param.Value = ordersFG(i, 5)
Param = cmd.Parameters.Add("@invoiceStatus", SqlDbType.Bit, 1)
Param.Value = 0
Next
Try
'Execute command
conn.Open()
Dim rows As Integer = cmd.ExecuteNonQuery
'Clear the flexgrid data
Dim rowCount
rowCount = ordersFG.Rows.Count
ordersFG.Rows.Count = ordersFG.Rows.Fixed
MsgBox("Data is already SAVE")
Catch ex As Exception
MsgBox(ex.ToString)
Return
Finally
conn.Close()
End Try