Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Need Help : DataGridView to SQL

$
0
0
I working on this program, in need help with it.

I have a program, which i input data into from different combo box. In when I'm done with inputing the data, I would like to save all the data thats in the datagridview to a SQL table. At the moment, I know i can add a source, but I to be able input data in the data gridview. The hit a button to save the data in the datagridview to a sql table.
I provided my code below. I know Im close with this, but I keep recieving a error message, which says the following; Must declare the scalar variable '@Line"




Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim SQLinsert As New SqlCommand
Dim SQLConnection As New SqlConnection
Dim cmd As New SqlCommand

SQLConnection.ConnectionString = "Server=10.53.252.221;UID=phasqladmin;PWD=i82dothis;Database=General KMMG Return log;Integrated ecurity=False"

SQLConnection.Open()

Try
For Each row As DataGridViewRow In DataGridView1.Rows
If row.IsNewRow Then
SQLinsert.CommandText = ("insert INTO Scrap_Report ([Line Area], [Shift]) values ( @Line Area, @Shift)")

SQLinsert.Connection = SQLConnection
'SQLinsert.Parameters.AddWithValue("@Line Area", TextBox1.Text)
'SQLinsert.Parameters.AddWithValue("@Shift", row.Cells(0).Value)
'SQLinsert.Parameters.AddWithValue("@Date", row.Cells(1).Value)

SQLinsert.Connection = SQLConnection
SQLinsert.ExecuteNonQuery()
End If
Next
SQLConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

End Sub

Viewing all articles
Browse latest Browse all 27554

Trending Articles