[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1256
  • Last Modified:

Form - Radio Buttons to store true/false value into database table

I have a visual basic form with several Yes/No Radio Buttons. I just want to store the value back into my table. Can anyone give me the VB designer code? I don't want to store a null value if the user selects the "No" button. I would to store a "False" value.
0
teustace
Asked:
teustace
1 Solution
 
jppintoCommented:
Try this code. If the Yes radio button is checked it will save "True" on your field, it's it's not check, it will save "False". Check the field type on your database to be Yes/No type.

jppinto
Public da As OleDb.OleDbDataAdapter
Public ds As New DataSet
 
sSQL = "SELECT * FROM [TableName]"
da = New OleDb.OleDbDataAdapter(sSQL, con)
ds.Clear()
da.Fill(ds, "TableName")
Dim dsNR As DataRow
Dim cb = New OleDb.OleDbCommandBuilder(da)
dsNR = ds.Tables("TableName").NewRow
 
If optYes.Checked Then
   dsNR.Item("Status") = True
Else
   dsNR.Item("Status") = False
End If
 
ds.Tables("TableName").Rows.Add(dsNR)
da.Update(ds, "TableName")
con.Close()

Open in new window

0
 
teustaceAuthor Commented:
Hi, many thanks for your response. As I am using a table adapter (I have other columns of data) so I assume I would slip this code into the Partial Class of the DataSet designer. However, I am unsure how to re-gig the code. My table adapter is called Deployments. Should I make this a Private Sub, and if so how? Also, I would want to be able to update values sometimes, so I'm not sure about the New Row part.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now