|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to reference Webform textbox controls in a for next loopI 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() You could build a custom collection of the target textboxes, and use
the index (or key) to retrieve the textbox. the for next loop would be something like this: <pseudocode> for x = 1 to 10 cmd.Parameters.AddWithValue("@Rank", MyCollection(x).Text) cmd.Parameters.AddWithValue("@OpenText", Me.txtQ1.Text) next x </pseudocode> Thanks, Seth Rowe Kevin wrote: Show quoteHide quote > 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()
class library
Trouble with mouse click File handling in VB How to Load string into mshtml object? Detect WiFi Networks Adding rows to a data table: Rows do not show up what method to use to add 1 day to a date (hotel reservation for one night by clicking on calender) PLEASE HELP - Executable properties - right click How do I calculate the date of the previous day given a date ( in "MM/dd/yy" format) how to compare two date variables? |
|||||||||||||||||||||||