Hello Experts,
This is my very first post here. so, please take easy on me.
I wrote a stored proc that takes 4 parameters and inserts into the db.
I have tested it using SSMS and it works great but I can't get it work with my .net app.
No errors but just doesn't work.
This is supposed to go live on Tuesday and I must give a demo by Monday.
The insert bit is the last task and is supposed to be easy.
Can someone please help?
Code is below and thanks a lot in advance.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim questld As HiddenField = DataList1.FindControl("HiddenField2")
For Each item As DataListItem In DataList1.Items
If item.ItemType = ListItemType.Item Or item.ItemType = ListItemType.AlternatingItem Then
Dim positionid As Integer
Dim choiceid As Integer = 0
Dim choicetext As String = ""'positionid = CType(item.FindControl("Label3"), Label).Text
positionid = CType(item.FindControl("HiddenField2"), HiddenField).Value
Dim anstype As HiddenField = item.FindControl("HiddenField1")
Select Case anstype.Value
Case "S"
Dim rbl As RadioButtonList = item.FindControl("RadioButtonList1")
choiceid = rbl.SelectedValue
SaveVotes(positionid, choiceid, choicetext, "")
Case "M"
Dim cbl As CheckBoxList = item.FindControl("CheckBoxList1")
For i As Integer = 0 To cbl.Items.Count - 1
If cbl.Items(i).Selected Then
choiceid = cbl.Items(i).Value
SaveVotes(positionid, choiceid, "NA", "")
End If
Next
Case "T"
Dim txt As TextBox = item.FindControl("TextBox1")
choicetext = txt.Text
SaveVotes(positionid, 0, choicetext, "")
End Select
End If
Next
DataList1.Visible = False
End Sub
Private Sub SaveVotes(ByVal qid As Integer, ByVal cid As Integer, ByVal ct As String, ByVal cuser As String)
Dim al As ArrayList = CType(Session("AnswerList"), ArrayList)
'Dim s As String
If al Is Nothing Then
Response.Redirect("Thanks.aspx")
End If
Dim connStr As String = ConfigurationManager.ConnectionStrings("BallotsConnectionString").ConnectionString
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand("InsertBallots", conn)
cmd.CommandType = CommandType.StoredProcedure
Dim p1 As New SqlParameter("@qid", qid)
Dim p2 As New SqlParameter("@cid", IIf(cid = 0, DBNull.Value, cid))
Dim p3 As New SqlParameter("@ct", IIf(ct = "", DBNull.Value, ct))
Dim p4 As New SqlParameter("@cuser", Session("UserName"))
cmd.Parameters.Add(p1)
cmd.Parameters.Add(p2)
cmd.Parameters.Add(p3)
cmd.Parameters.Add(p4)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End Sub