I want to insert a record in a database
with two groupbox
. groupbox1
(has Male and female radio buttons
) and groupbox2
( has New students and old students radio buttons
)
In this case there will be four possible input the needs to be check
- Male and old students
- Male and new students
- Female and old students
- Female and New students
Normally I will check each radio button individually just like this
If rbtMale.Checked And rbtOld.Checked Then
Dim OldStudent = rbtOld.Text.ToString
Dim Male = rbtMale.Text.ToString
Using cmd As New SqlClient.SqlCommand("dbo.uspInsert", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@StudPic", SqlDbType.Image))
If (Not String.IsNullOrEmpty(Me.Name) AndAlso System.IO.File.Exists(a.FileName)) Then
cmd.Parameters("@StudPic").Value = System.IO.File.ReadAllBytes(a.FileName)
cmd.Parameters.Add("@SurName", SqlDbType.VarChar, 100).Value = txtStudLN.Text
cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 100).Value = txtStudFN.Text
cmd.Parameters.Add("@Gender", SqlDbType.VarChar, 100).Value = Male
cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = OldStudent
cmd.ExecuteNonQuery()
MsgBox("Save Record New record Successfully")
End If
End Using
End If
But I think there is smart way to check which radio button
being checked in a groupbox
and insert it in a database
. Below are some codes that gives me idea about this but the problem is that i do not know how to pass the value in a groupbox
then insert this in my db. Any help would be very much appreciated. Thanks
For Each Ctrl In GroupBox1.Controls
If Ctrl.checked Then MsgBox(Ctrl.name)
Next