Friday, March 30, 2012

problems with two insert queries in a page

Hello

I have a question about something odd happening with an insert query.

I am working on a password protected site and I want to moniter general student use. I have an on page load even which picks up their user id and the url and sends it to the database

Because my site is a beta site, I also want the users to be able to add their comments as and when they want, so I built a small feedback form on each page.

The quick feedback form has a panel to hide it until a user clicks on a radio button and this reveals a text box and a submit button.

However, since I have added this second sql connection with an insert, I now get an error message I was getting a connection string error when I tried to point at the connection string in the web.config file, so I put the full path in to the database and now I get an error message that says the conTrackUser has not been declared, but as you can see from the code it certainly has. So I'm beginning to thing that the error is something entierly different, but that's probably me being thick.

I've pasted the two insert blocks below, I can't see anything wrong with them, but then I'm mostly groping about in the dark with asp.net.

Is it not possible to have two insert commands on a page? That would be daft.

Here is the code.

Track and initilize the radio button and panel for the feedback:


Sub Page_Load(Sender As Object, E As EventArgs)
Dim UserID as String = session("UserID")
pnlQuickFeedback.Visible = False
If Not Page.IsPostback Then
Dim conTrackUser As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand

conTrackUser = New SqlConnection("server='server'; user id='me'; password='nuts'; database='database'")

cmdInsert = New SqlCommand("TrackUser5530", conTrackUser)
cmdInsert.CommandType = CommandType.StoredProcedure
cmdInsert.Parameters.Add("@.UserIdentity", session("UserID") )
cmdInsert.Parameters.Add("@.URL", Request.Url.AbsoluteUri )

conTrackUser.Open()
cmdInsert.ExecuteNonQuery()
conTrackUser.Close()
End If
End Sub


The sub for the feedback:

Sub SubmitFbbtn_Click(Sender As Object, E As EventArgs)
Dim UserID as String = session("UserID")

'If Not Page.IsPostback Then
Dim conQuickFeedback As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand

conQuickFeedback = New SqlConnection("server='server'; user id='me'; password='nuts'; database='database'")

cmdInsert = New SqlCommand("QuickComments5530", conQuickFeedback)
cmdInsert.CommandType = CommandType.StoredProcedure
cmdInsert.Parameters.Add("@.UserIdentity", session("UserID") )
cmdInsert.Parameters.Add("@.Comments", txtComments.text)
cmdInsert.Parameters.Add("@.URL", Request.Url.AbsoluteUri )

conQuickFeedback.Open()
cmdInsert.ExecuteNonQuery()
conQuickFeedback.Close()
pnlQuickFeedback.Visible = False
feedbackFormbtn.Visible = True
feedbackFormbtn.Checked = False
End Sub


thanksTry using

data source='server'; user id='me'; password='nuts'; initial catalog='database'

No comments:

Post a Comment