Hi,
I have a GridView with several rows of data and I want this data to be inserted into a SQL Server Express table using VWD Express and
VB.
The problem is that I don't know how to index the GridView. Here is what I have in my code behind page:
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim conn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings("ekodbConnectionString").C onnectionString)
Dim row As Integer
Dim cust_ID As Integer
Dim firstname As String
Dim lastname As String
For row = 1 To 10
cust_ID = GridView1[row,1].Item 'Needs to be corrected!
firstname = GridView1[row,2].Item 'Needs to be corrected!
lastname = GridView1[row,3].Item 'Needs to be corrected!
Dim cmd As SqlCommand = New SqlCommand("INSERT INTO customers VALUES (" & cust_ID & ", " & firstname & ", " & lastname & ")", conn)
conn.Open()
cmd.ExecuteScalar()
conn.Close()
Next
End Sub
1. So, instead of the errorenous lines of code for retrieving the GridView values, what should I write?
Two additional questions:
2. In the code above, I stated For row = 1 To 10. Can I write While row <> nil or something to get everything?
3. I use cmd.ExecuteScalar, which works but is not really making sense as I don't try to get a value from the sub. Is there anything else that works to get the Sql going?
Thanks very much in advance for help with any of this!
Pettrer,Sweden
Coding is indeed a nine-to-five job; nine pm to five am.