K
Kevin
ASP.NET 2.0
I have code that updates a database from a number of textboxes on a web
form.
I've had to hard coded references to my web form textboxes. I'd like to
know how I can reference them via a for next loop.
For example, each time I give my command parameters a value I hard coded the
textbox.text reference.
cmd.Parameters.AddWithValue("@Rank", Me.ddlQ1.Text)
cmd.Parameters.AddWithValue("@OpenText", Me.txtQ1.Text)
I'd like to use a for next loop something like this:
for x = 1 to 10
cmd.Parameters.AddWithValue("@Rank", Me.ddlQ" & x & ".Text)
cmd.Parameters.AddWithValue("@OpenText", Me.txtQ" & x & ".Text)
next
What is the correct syntax for this.
Thanks in advance.
Kevin
Sample:
Private Sub SaveWork()
'This code will save all responces on this form.
Dim sSQL As String
Dim cn As New SqlConnection(Conn.ConnString)
Dim cmd As New SqlCommand(sSQL, cn)
' ------------------------------------------------------------
cmd.CommandType = System.Data.CommandType.Text
cmd.Connection = cn
cmd.Parameters.AddWithValue("@Rank", Me.ddlQ1.Text)
cmd.Parameters.AddWithValue("@OpenText", Me.txtQ1.Text)
sSQL = "UPDATE Responses"
sSQL = sSQL & " SET Rank = @Rank, "
sSQL = sSQL & " OpenText = @OpenText"
sSQL = sSQL & " WHERE ( UserID = '" & smUserID & "'"
sSQL = sSQL & " AND DocumentID = " & CInt(smDocumentID)
sSQL = sSQL & " AND QuestionNumber = 1)"
cmd.CommandText = sSQL
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
I have code that updates a database from a number of textboxes on a web
form.
I've had to hard coded references to my web form textboxes. I'd like to
know how I can reference them via a for next loop.
For example, each time I give my command parameters a value I hard coded the
textbox.text reference.
cmd.Parameters.AddWithValue("@Rank", Me.ddlQ1.Text)
cmd.Parameters.AddWithValue("@OpenText", Me.txtQ1.Text)
I'd like to use a for next loop something like this:
for x = 1 to 10
cmd.Parameters.AddWithValue("@Rank", Me.ddlQ" & x & ".Text)
cmd.Parameters.AddWithValue("@OpenText", Me.txtQ" & x & ".Text)
next
What is the correct syntax for this.
Thanks in advance.
Kevin
Sample:
Private Sub SaveWork()
'This code will save all responces on this form.
Dim sSQL As String
Dim cn As New SqlConnection(Conn.ConnString)
Dim cmd As New SqlCommand(sSQL, cn)
' ------------------------------------------------------------
cmd.CommandType = System.Data.CommandType.Text
cmd.Connection = cn
cmd.Parameters.AddWithValue("@Rank", Me.ddlQ1.Text)
cmd.Parameters.AddWithValue("@OpenText", Me.txtQ1.Text)
sSQL = "UPDATE Responses"
sSQL = sSQL & " SET Rank = @Rank, "
sSQL = sSQL & " OpenText = @OpenText"
sSQL = sSQL & " WHERE ( UserID = '" & smUserID & "'"
sSQL = sSQL & " AND DocumentID = " & CInt(smDocumentID)
sSQL = sSQL & " AND QuestionNumber = 1)"
cmd.CommandText = sSQL
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()