Welcome to WebmasterWorld Guest from 54.90.204.233

Forum Moderators: ocean10000

Message Too Old, No Replies

Two Queries in VB

     
4:58 pm on Jul 21, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


Can anyone help me with this. I have the following code

Function pay_membership(ByVal PaymentID As Integer)
'update the users table to set the user to a member
Dim userid As Integer = Convert.ToInt16(userDD.SelectedValue.ToString)
Dim memberSql As String = "update tblUsers set ismember = true where userid = " & userid
Dim memberCommand As New Data.OleDb.OleDbCommand(memberSql, myConnection)
'make an entry in the membership table
Dim success As Boolean = True
Dim membershipSQL As String = "insert into tblRegistrations (UserID, PaymentID, AmountDue, DateRegistered) values (" & userDD.SelectedValue & ", " & PaymentID & ", " & paymentAmountTBox.Text & ", #" & Today.Date.ToString & "#)"
Dim membershipCommand As New Data.OleDb.OleDbCommand(membershipSQL, myConnection)

Try
myConnection.Open()
membershipCommand.ExecuteNonQuery()
Catch ex As Exception
messageLabel.Text = "There has been an error.<br /><Br />" & ex.ToString & "<br /><Br />" & membershipSQL
success = False
Finally
myConnection.Close()
End Try
'Try
' myConnection.Open()
' memberCommand.ExecuteNonQuery()
'Catch ex As Exception
' messageLabel.Text = "There has been an error.<br /><Br />" & ex.ToString & "<br /><Br />" & membershipSQL
' success = False
'Finally
' myConnection.Close()
'End Try

Return success
End Function

TherSee the part that is commented out. If I run the page with the commented part like it is it works fine. As soon as I try to run the second query I get this error

there has been an error.

System.Data.OleDb.OleDbException: No value given for one or more required parameters. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at manualpayments.pay_membership(Int32 PaymentID) in \\intellicom05\Company\Customers\NebraskaStateReadingAssociation\Web\nereads.org\Site\www\private\admin\manualpayments.aspx.vb:line 195

insert into tblRegistrations (UserID, PaymentID, AmountDue, DateRegistered) values (4199, 3841, 20, #7/21/2009 12:00:00 AM#)

What I don't understand is why the first query errors when I add the second. Is it because I am adding two queries? I know both queries are correct because I have printed them on the page and tested them manually. Thanks,

4:19 pm on July 26, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


Dim memberSql As String = "update tblUsers set ismember = true where userid = " & userid

with

Dim memberSql As String = "update tblUsers set ismember = true where userid = " & userDD.SelectedValue

4:09 pm on July 27, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


Thanks for the reply, once again, the problem existed between the chair and the computer. I had made up update to our testing sql server database, but had not copied the change over to the live server. Therefore, when I was trying to add the value, that column didn't exist. It would have been solved a lot faster if the error reporting wasn't so cryptic. Thanks,
5:30 pm on July 27, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


Been there Done that myself many of time.

I learned to save Sql Changes after every time I knowingly change the DB on the development server, and then play this changes back on the production. I also wrote a custom program to do a schema dump of the tables, their structure, relations, and stored procedures. I use this to dump the exact layout of the development DB to be later compared against the production. Doing this has saved me a lot of problems because it makes it easier determining what I missed if anything.