如何将标记单选按钮保存到我的数据库访问

时间:2017-03-05 14:44:09

标签: vb.net radio-button access

我只想知道如何将选定的单选按钮保存到我的访问数据库,例如男性和女性选项...一旦我标记男性,男性文本将保存到数据库这是我的运行代码:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Try
        Dim s As Boolean
        If rdbMale.Checked = True Then
            s = True
        ElseIf rdbFemale.Checked = True Then
            s = False
        End If

        Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
        Dim breader As New BinaryReader(fsreader)
        Dim imgbuffer(fsreader.Length) As Byte
        breader.Read(imgbuffer, 0, fsreader.Length)
        fsreader.Close()
        strsql = "insert into students (Stdnt_ID, Fname, Lname, Mname, Gender, Dob, Depart, Crse, Major, Sec, Address, Contact_Number, StudentPic) values (@dtaID, @dtaFname, @dtaLname, @dtaMname, @dtaGend, @dtaDob, @dtaDepart, @dtaCrse, @dtaMajor, @dtaSec,@dtaAddress, @dtaCont, @dtafile)"
        cmd.CommandText = strsql
        cmd.Connection = (OleCn)
        cmd.Parameters.AddWithValue("@dtaID", IDtxts.Text)
        cmd.Parameters.AddWithValue("@dtaFname", nmetxt.Text)
        cmd.Parameters.AddWithValue("@dtaLname", lastxt.Text)
        cmd.Parameters.AddWithValue("@dtaMname", mitxt.Text)
        cmd.Parameters.AddWithValue("@dtaGend", s)
        cmd.Parameters.AddWithValue("@dtaDob", dttxt.Text)
        cmd.Parameters.AddWithValue("@dtaDepart", dpttxt.Text)
        cmd.Parameters.AddWithValue("@dtaCrse", crsetxt.Text)
        cmd.Parameters.AddWithValue("@dtaMajor", mjortxt.Text)
        cmd.Parameters.AddWithValue("@dtaSec", sectxt.Text)
        cmd.Parameters.AddWithValue("@dtaAddress", addtxt.Text)
        cmd.Parameters.AddWithValue("@dtaCont", contxt.Text)
        cmd.Parameters.AddWithValue("@dtafile", imgbuffer)
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        MsgBox("Thank You! A New Student is Successfully Registered")
    Catch ex As Exception
        MsgBox("Please Fill up All the required information")
    End Try
End Sub

任何建议和答案都将受到高度赞赏..我只是一个初学者,谢谢你们

0 个答案:

没有答案