Hi,
i have a form in vb.net and it has two groups of radio buttons and once a selection is made i need to update it and save it into the database(ms access). i am failing to get the information to save into the access database but instead i am getting an error on the command execute query. here is my code:
[code]
strSQL = "INSERT INTO development VALUES (" & Label2.Text & "','" & Label3.Text & "','" & Label4.Text & "','" & Label5.Text & "','" & Label6.Text & "','" & Label20.Text & "','" & Label21.Text & "','" & RadioButton5.Text & "','" & RadioButton6.Text & "'," & devstaffid.Text & ",'" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox5.Text & "','" & dateindev.Text & ")"
oledbcon.Open()
Dim cmd As New OleDbCommand(strSQL, oledbcon)
cmd.ExecuteNonQuery()
MsgBox("Development Info Saved Successfully !", MsgBoxStyle.Information, "Records Management System")
oledbcon.Close()
[\code]
the error is on this line:
[code]cmd.ExecuteNonQuery()
[\code]
load radio button value into databasesave radio button value into access database
Page 1 of 1
11 Replies - 23594 Views - Last Post: 05 April 2010 - 12:02 AM
Replies To: load radio button value into database
#2
Re: load radio button value into database
Posted 04 May 2009 - 03:40 AM
use this code
RadioButton5.Value
#3
Re: load radio button value into database
Posted 04 May 2009 - 04:37 AM
The RadioButton control returns a boolean value, which means True or False without the single quotes. Therefore your code should read:
Please note there is a single quote just before the last closed parenthesis. You forgot to put one.
strSQL = "INSERT INTO development VALUES (" & Label2.Text & "','" & Label3.Text & "','" & Label4.Text & "','" & Label5.Text & "','" & Label6.Text & "','" & Label20.Text & "','" & Label21.Text & "'," & RadioButton5.Value & "," & RadioButton6.Value & "," & devstaffid.Text & ",'" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox5.Text & "','" & dateindev.Text & "')"
oledbcon.Open()
Dim cmd As New OleDbCommand(strSQL, oledbcon)
cmd.ExecuteNonQuery()
MsgBox("Development Info Saved Successfully !", MsgBoxStyle.Information, "Records Management System")
oledbcon.Close()
Please note there is a single quote just before the last closed parenthesis. You forgot to put one.
#4
Re: load radio button value into database
Posted 04 May 2009 - 11:11 PM
DataPriest, on 4 May, 2009 - 12:37 PM, said:
The RadioButton control returns a boolean value, which means True or False without the single quotes. Therefore your code should read:
Please note there is a single quote just before the last closed parenthesis. You forgot to put one.
strSQL = "INSERT INTO development VALUES (" & Label2.Text & "','" & Label3.Text & "','" & Label4.Text & "','" & Label5.Text & "','" & Label6.Text & "','" & Label20.Text & "','" & Label21.Text & "'," & RadioButton5.Value & "," & RadioButton6.Value & "," & devstaffid.Text & ",'" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox5.Text & "','" & dateindev.Text & "')"
oledbcon.Open()
Dim cmd As New OleDbCommand(strSQL, oledbcon)
cmd.ExecuteNonQuery()
MsgBox("Development Info Saved Successfully !", MsgBoxStyle.Information, "Records Management System")
oledbcon.Close()
Please note there is a single quote just before the last closed parenthesis. You forgot to put one.
when i write radiobutton5.value gives error saying 'value' is not a member of 'System.windows.forms.radiobutton'
#5
Re: load radio button value into database
Posted 04 May 2009 - 11:26 PM
by the way, its the other slash to end the code. / not \
#6
Re: load radio button value into database
Posted 04 May 2009 - 11:33 PM
#7
Re: load radio button value into database
Posted 05 May 2009 - 01:27 AM
The best way is to save a value into variable and then store the value as is in the insert statement here is an example
Dim rbtnValue as string
If RadioButton.checked then
rbtnValue = RadioButton.Value
else
'''
end if
then
"Insert into Table values ('" & rbtnValue&"') "
-------------
This could solve your problem
Dim rbtnValue as string
If RadioButton.checked then
rbtnValue = RadioButton.Value
else
'''
end if
then
"Insert into Table values ('" & rbtnValue&"') "
-------------
This could solve your problem
#8
Re: load radio button value into database
Posted 05 May 2009 - 12:05 PM
sakhr_99, on 5 May, 2009 - 09:27 AM, said:
The best way is to save a value into variable and then store the value as is in the insert statement here is an example
Dim rbtnValue as string
If RadioButton.checked then
rbtnValue = RadioButton.Value
else
'''
end if
then
"Insert into Table values ('" & rbtnValue&"') "
-------------
This could solve your problem
Dim rbtnValue as string
If RadioButton.checked then
rbtnValue = RadioButton.Value
else
'''
end if
then
"Insert into Table values ('" & rbtnValue&"') "
-------------
This could solve your problem
hi i tried RadioButton.Value and it still gives the same error, it does not recognise .Value for radio button
#9
Re: load radio button value into database
Posted 21 June 2009 - 09:18 PM
melodimoeti, on 5 May, 2009 - 11:05 AM, said:
sakhr_99, on 5 May, 2009 - 09:27 AM, said:
The best way is to save a value into variable and then store the value as is in the insert statement here is an example
Dim rbtnValue as string
If RadioButton.checked then
rbtnValue = RadioButton.Value
else
'''
end if
then
"Insert into Table values ('" & rbtnValue&"') "
-------------
This could solve your problem
Dim rbtnValue as string
If RadioButton.checked then
rbtnValue = RadioButton.Value
else
'''
end if
then
"Insert into Table values ('" & rbtnValue&"') "
-------------
This could solve your problem
hi i tried RadioButton.Value and it still gives the same error, it does not recognise .Value for radio button
i'm having the same problem... anyone have other suggestion? thanks
This post has been edited by k4k45h1: 21 June 2009 - 09:20 PM
#10
Re: load radio button value into database
Posted 24 June 2009 - 02:01 AM
you can also use
RadioButton.Text
to store text that appear in RadioButton
ex : if you want to Store Male as text in DB
and you have radio Button called Male right next beside it as Text property
user
rbtn.Text
to store the value
RadioButton.Text
to store text that appear in RadioButton
ex : if you want to Store Male as text in DB
and you have radio Button called Male right next beside it as Text property
user
rbtn.Text
to store the value
#11
Re: load radio button value into database
Posted 24 June 2009 - 09:31 AM
Yeah, you're still trying to use .Value which isn't a property for a RadioButton. You want to use .Checked.
Then in your SQL Insert Statement change your RadioButton.Values to the variables that correspond with them.
Hope this helps...
Dim strRadioText as String If RadioButton1.Checked = True Then strRadioText = RadioButton1.Text Elseif RadioButton2.Checked = True Then strRadioText = RadioButton2.Text Else strRadioText = RadioButton3.Text End If
Then in your SQL Insert Statement change your RadioButton.Values to the variables that correspond with them.
Hope this helps...
This post has been edited by eworm: 24 June 2009 - 11:37 AM
#12 Guest_maverick*
Re: load radio button value into database
Posted 05 April 2010 - 12:02 AM
can i have the same code written in vba..?
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|