i ve got two radiobuttons one labelled male and the other labelled female and a client is supposed to choose which gender they are and insert it into the other database along with other information. I want to know how I can insert the chosen value (male or female) into the database

Dim Conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\WBS2020\WBS2020\WBS2020\WBS2020\WBS2020_22-02-2012.accdb;persist security info = false")
        Dim iSql As String = "Insert into CompanyDetails (code,description)  VALUES ('" & txtCode.Text & "', '" & txtDescription.Text & "' )"
        Dim query2 As String = "Select @@Identity"
        Dim ID As Integer
        Dim cmd As New OleDbCommand(iSql, Conn)
        Conn.Open()
        cmd.ExecuteScalar()
        cmd.CommandText = query2
        ID = cmd.ExecuteScalar()

You need to check which radio button is checked before saving and accordingly pass the values to DB

Use parametrized query, and define in the parameter which value to choose, like (example code):

Dim query As String = "INSERT INTO MyTable VALUES (value1 = @param1, value2 = @param1)"
'value 1 is exmaple id column
'value 2 is the male of female.
Dim conn As New SqlConnection("connString")
Dim cmd As SqlComamnd = New SqlCommand(query, conn)
cmd.Parameters.Add("@param1", SqlDbType.Int).Value = 1
'some example num for id
cmd.Parameters.Add("@param2", SqlDbType.VarChar, 50).Value = If(radiobutton1.Checked, "male", "female")
'this code will insert string "male" if radiobutton1 is checked
'if radiobutton2 is checked, "female" string will be inserted!

hello!
you can save value of radio button by using radiobutton1.checked , and as you have prob which radio button is selected by the user , then there are two ways to perform this ,
1- you can use two fields in your database , male and female , because radio button always provide yes or no values or true or false values , so if you used single field name gender then there will be prob .
2- you can set the datatype of your gender field varchar or string , and at the coding end you can do this

if radiobuttonMale.checked = true then 
'you enter in your database word male as string 
else
'you enter in your database word female as string 
end if

and there is another way to do this , use combo box , set two values , male and female , now in your database you have a single field name gender , set datatype varchar or string , and save the selected value in your database . like this combobox.text.
and in last in your code there is no column is define for your gender insertion ,
please recheck your code again :)

Best Regards

Sir , i just give some suggestions so that he can better analyse his requirement and adopt best solution for his prob :)

Best Regards Sir

This article has been dead for over six months. Start a new discussion instead.