Hey everyone, my issue is a little strange, I have a form that has checkboxes, and depending on the selection, a textbox might appear for further info. I want to loop through the controls that have been selected, if it's only a checkbox than just add the Value of the checkbox, if there is also a textbox associated, add the text to the database as well. I keep getting the error that @chkText either has already been set, or that i have to declare the scalar variable @chkText. I dont know if this is even possible or if my approach is completely wrong, but any help is appreciated.
Also, I dont know if this will help, but when I comment out all of the database stuff, my message boxes that i have set up for testing work perfectly. They iterate through and they pop-up the Checkbox value, followed by corresponding textbox values in the exact right order;
Here is the code with the SQL stuff commented out;
Protected Sub Button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button7.Click
InsertPatientInfo.Insert()
InsInqInfo.Insert()
InsOtherInfo.Insert()
InsClinInfo.Insert()
InsInquiryInfo.Insert()
'Dim myConn As New SqlConnection("Data Source=W0121968;Initial Catalog=ResInquiryDev;Integrated Security=True;Pooling=False")
'Dim queryCommand As SqlCommand = myConn.CreateCommand()
'myConn.Open()
'queryCommand.CommandText = "INSERT into tblReferral(RefInquiryID, RefSource, RefSourceText)VALUES(@InquiryID, @chkText, @txtText)"
'queryCommand.Parameters.Add("@InquiryID", SqlDbType.Int)
'queryCommand.Parameters("@InquiryID").Value = Convert.ToInt32(Session("NewInquiryID"))
For Each ctrl As Control In Panel7.Controls
If TypeOf ctrl Is CheckBox Then
If CType(ctrl, CheckBox).Checked = True Then
For i = 0 To ctrl.Controls.Count
Dim str As String
str = DirectCast(ctrl, CheckBox).Text
MsgBox(str, MsgBoxStyle.Critical)
'queryCommand.Parameters.Add("@chkText", SqlDbType.VarChar)
'queryCommand.Parameters("@chkText").Value = str.ToString
Next
End If
End If
If TypeOf ctrl Is TextBox Then
If CType(ctrl, TextBox).Text <> "" Then
For i = 0 To ctrl.Controls.Count
Dim txtstring As String
txtstring = DirectCast(ctrl, TextBox).Text
MsgBox(txtstring, MsgBoxStyle.Critical)
'queryCommand.Parameters.Add("@txtText", SqlDbType.VarChar)
'queryCommand.Parameters("@txtText").Value = txtstring.ToString
Next
End If
End If
'queryCommand.ExecuteNonQuery()
Next
'myConn.Close()
MultiView1.ActiveViewIndex = 4
End Sub