load radio button value into database

save radio button value into access database

Page 1 of 1

11 Replies - 27332 Views - Last Post: 05 April 2010 - 12:02 AM Rate Topic: -----

#1 melodimoeti  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 20-April 09

load radio button value into database

Posted 04 May 2009 - 03:29 AM

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]

Is This A Good Question/Topic? 0
  • +

Replies To: load radio button value into database

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: load radio button value into database

Posted 04 May 2009 - 03:40 AM

use this code
RadioButton5.Value


Was This Post Helpful? 1
  • +
  • -

#3 DataPriest  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 57
  • Joined: 29-April 09

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:

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.
Was This Post Helpful? 0
  • +
  • -

#4 melodimoeti  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 20-April 09

Re: load radio button value into database

Posted 04 May 2009 - 11:11 PM

View PostDataPriest, 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:

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'
Was This Post Helpful? 1
  • +
  • -

#5 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

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 \
Was This Post Helpful? 0
  • +
  • -

#6 melodimoeti  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 20-April 09

Re: load radio button value into database

Posted 04 May 2009 - 11:33 PM

View Postfirebolt, on 5 May, 2009 - 07:26 AM, said:

by the way, its the other slash to end the code. / not \

thanks for the correction
Was This Post Helpful? 0
  • +
  • -

#7 sakhr_99  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 01-March 09

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
Was This Post Helpful? 0
  • +
  • -

#8 melodimoeti  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 20-April 09

Re: load radio button value into database

Posted 05 May 2009 - 12:05 PM

View Postsakhr_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


hi i tried RadioButton.Value and it still gives the same error, it does not recognise .Value for radio button
Was This Post Helpful? 1
  • +
  • -

#9 k4k45h1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-June 09

Re: load radio button value into database

Posted 21 June 2009 - 09:18 PM

View Postmelodimoeti, on 5 May, 2009 - 11:05 AM, said:

View Postsakhr_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


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

Was This Post Helpful? 0
  • +
  • -

#10 sakhr_99  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 01-March 09

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
Was This Post Helpful? 0
  • +
  • -

#11 eworm  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 64
  • Joined: 17-March 09

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.

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

Was This Post Helpful? 0
  • +
  • -

#12 Guest_maverick*


Reputation:

Re: load radio button value into database

Posted 05 April 2010 - 12:02 AM

can i have the same code written in vba..?
Was This Post Helpful? 0

Page 1 of 1