Hello,
Take one boolean variable. Set it to True/False according to Selected value.
Like, for "Yes" selected set it to "True" other wise "False" (Using If/else)
And then pass this boolean variable to parameter.
Command.Parameters.AddWithValue("LikeJob", BooleanVariable)
Regards
Kuldeep Deokule
Thanks for the reply. I'm not sure I follow you. If I set a variable to Boolean, how can I determine it's selected value? Can you give me a code example?
Hello,
Post your non-working code here. So I'll incorporate boolean variable and related logic in it. This will be more helpful to you than any other example.
Regards
Kuldeep Deokule
I think I figured it out, but now I'm having problems updating the database. I'm trying to refer to the users email address that I have in the Email Label. Any ideas why that won't populate the field:
Protected
Sub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.ClickDim varBusAsBoolean'varBus if thenIf rblBus.SelectedValue ="Yes"Then
varBus =
TrueElseIf rblBus.SelectedValue ="No"ThenvarBus =
FalseEndIfDim ConnStringAsString ="Provider = Microsoft.Jet.OLEDB.4.0; Data Source=MyDataBase.mdb"Dim ConnAsNew Data.OleDb.OleDbConnection(ConnString)Dim CommStringAsString ="UPDATE tblPart SET BusPass = rblBusWHERE Email = lEmail.text"Dim CommandAsNew Data.OleDb.OleDbCommand(CommString, Conn)Command.Parameters.AddWithValue(
"BusPass", varBus)Command.Parameters.AddWithValue("Email", lEmail.Text)
Conn.open()
Conn.Close()EndSub
barryman9000:
Dim CommStringAsString ="UPDATE tblPart SET BusPass = rblBusWHERE Email = lEmail.text"
Make change in Commstring as shown below:
Dim CommStringAsString ="UPDATE tblPart SET BusPass =?WHERE Email = ?"
I am assuming BusPass and Email fields names in table.
Regards
Kuldeep Deokule
Thanks again. I'm actually trying to update the fields that correspond to the users Email address, which is in a Label called lEmail.
I have a multiple page "sign up" form, and once they hit the submit button on the first page, the next page has my Yes/No radio button, and I pass their email address from the first page textbox, to a label on the next page. So I'm trying to update their info, to just add the BusPass yes/no data.
Any suggestions?
Hello,
I understood what you are trying. But...
Do you changed commstring as I suggested?
If yes, Are you facing any problems/errors. Just describe about that.
Regards
Kuldeep Deokule
I changed the CommString, but I just can't get the BusPass field to submit any data. I'm not getting any errors, after clicking submit it goes to my "thanks for registering" page, but nothing is entered into the DB.
Can't I update the BusPass field for this specific user, by using this:
Dim
varBusAsBooleanIf rblBus.SelectedValue ="Yes"Then
varBus =True
ElseIf rblBus.SelectedValue ="No"Then
varBus =False
EndIf
"UPDATE tblPart SET BusPass = ?,
WHERE Email = ?"Command.Parameters.AddWithValue("BusPass",varBus)
Command.Parameters.AddWithValue("Email",lEmail.Text)
Where lEmail is the users email address?
barryman9000:
"UPDATE tblPart SET BusPass = ?,
WHERE Email = ?"
I've tested the code given by me and it's working fine with database. Also remove comma after "SET BusPass=?".(It is in your posted code that I quoted above)
For you, Here is tested code developed by me.:
ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.ClickDim varBusAsBoolean'varBus if thenIf rblBus.SelectedValue ="Yes"Then
varBus =
TrueElseIf rblBus.SelectedValue ="No"ThenvarBus =
FalseEndIfDim ConnStringAsString = ConfigurationManager.ConnectionStrings _(
"Conn").ConnectionStringDim ConnAsNew Data.OleDb.OleDbConnection(ConnString)Dim CommStringAsString ="UPDATE tblPart SET BusPass = ? WHERE Email = ?"Dim CommandAsNew Data.OleDb.OleDbCommand(CommString, Conn)Command.Parameters.AddWithValue(
"BusPass", varBus)Command.Parameters.AddWithValue(
"Email", lEmail.Text)Conn.Open()
Command.ExecuteNonQuery()
Conn.Close()
EndSub
Regards
Kuldeep Deokule
Thanks for taking the time to help me out. I have the same thing, but it still doesn't work for me. It only works for me if I have the UPDATE statement written like this:
UPDATE tblPart SET [BusPass] = ? WHERE
= Email
but if I have more than one record in the DB, the BusPass field updates every record, not just the field that corresponds to the lEmail.text control. Any ideas?
That is:
UPDATE tblPart SET [BusPass] = ? WHERE Email = Email
but the first Email is in [].
That is:
UPDATE tblPart SET [BusPass] = ? WHERE Email = Email
but the first Email is in [ ].
Hello,
Instead of paramaterized query try following code,
ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.ClickDim varBusAsBoolean
'varBus if thenIf rblBus.SelectedValue ="Yes"Then
varBus =
TrueElseIf rblBus.SelectedValue ="No"ThenvarBus =
FalseEndIfDim ConnStringAsString = ConfigurationManager.ConnectionStrings _(
"Conn").ConnectionStringDim ConnAsNew Data.OleDb.OleDbConnection(ConnString)Dim CommStringAsString ="UPDATE tblPart SET BusPass =" & varBus & " WHERE Email ='" & lEmail.Text & "'"Conn.Open()
Command.ExecuteNonQuery()
Conn.Close()
EndSubRegards
Kuldeep Deokule
Thanks again. Without the
Dim
CommandAsNew Data.OleDb.OleDbCommand(CommString, Conn)I get an error, because of the Command.ExecuteNonQuery. If I leave the Command Variable in, I get an error that I'm missing a parameter.
How do I get around that?
No comments:
Post a Comment