Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Radio Button insert option

Radio Button insert option

Scheduled Pinned Locked Moved Visual Basic
databasehelpcsharpsql-server
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rrrriiizz
    wrote on last edited by
    #1

    hello all, Am creating employees master data using vb.net and sql server. in my screen i have lot of radio button for male /female selection and some yes/no selection. my problem is how to insert this radiobutton values to the database.according to the user selection(yes/no). Here i have Attached My coding Please help me........... INSERT OPTION CODE

     Private Sub btnins_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnins.Click
            con.Open()
            str = "Insert into EmployeeMaster values('" & txtname.Text & "','" & txtfname.Text & "','" & dtdob.Text & "','" & gencom.Text & "','" & txtqual.Text & " ','" & txtbg.Text & " ','" & martcom.Text & "','" & txtadd.Text & "',' " & txtcadd.Text & " ','" & txtpho.Text & "','" & txtmob.Text & "',' " & txtemail.Text & " ','" & txtpp.Text & " ','" & txtpv.Text & " ',' " & txteno.Text & " ',' " & depcom.Text & " ', ' " & descom.Text & " ',' " & dtdoj.Text & " ','" & catcom.Text & "','" & mopcom.Text & "','" & txtac.Text & "','" & byes.Text & "',' " & txtbv.Text & "',' " & txtcdue.Text & "','" & txtcdate.Text & "','" & txtesino.Text & "','" & txtpfno.Text & "','" & expyes.Text & "',' " & detcom.Text & "','" & txtpc.Text & "','" & txtnc.Text & "' )"
            cmd = New OdbcCommand(str, con)
            cmd.ExecuteNonQuery()
            'check()
            MsgBox("Inserted")
            clear()
            con.Close()
        End Sub
    

    VIEW OPTION CODE

    con.Open()
            str = "select * from EmployeeMaster where Name='" & namecom.Text & "'"
            cmd = New OdbcCommand(str, con)
            dr = cmd.ExecuteReader
            If dr.Read Then
                txtname.Text = dr.GetValue(0)
                txtfname.Text = dr.GetValue(1)
                dtdob.Text = dr.GetValue(2)
                gencom.Text = dr.GetValue(3)
                txtqual.Text = dr.GetValue(4)
                txtbg.Text = dr.GetValue(5)
                martcom.Text = dr.GetValue(6)
                txtadd.Text = dr.GetValue(7)
                txtcadd.Text = dr.GetValue(8)
                txtpho.Text = dr.GetValue(9)
                txtmob.Text = dr.GetValue(10)
                txtemail.Text = dr.GetValue(11)
                txtpp.Text = dr.GetValue(12)
                txtpv.Text = dr.GetValue(13)
                enocom.Text = dr.GetValue(14)
                depcom.Text = dr.GetValue(15)
                descom.Text = dr.GetValue(16)
                dtdoj.Text = dr.GetValue(17)
                catcom.Text = dr.GetValue(18)
                mopcom.Text = dr.GetValue(19)
                txtac.Text = dr.GetValue(20)
    
    C 1 Reply Last reply
    0
    • R rrrriiizz

      hello all, Am creating employees master data using vb.net and sql server. in my screen i have lot of radio button for male /female selection and some yes/no selection. my problem is how to insert this radiobutton values to the database.according to the user selection(yes/no). Here i have Attached My coding Please help me........... INSERT OPTION CODE

       Private Sub btnins_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnins.Click
              con.Open()
              str = "Insert into EmployeeMaster values('" & txtname.Text & "','" & txtfname.Text & "','" & dtdob.Text & "','" & gencom.Text & "','" & txtqual.Text & " ','" & txtbg.Text & " ','" & martcom.Text & "','" & txtadd.Text & "',' " & txtcadd.Text & " ','" & txtpho.Text & "','" & txtmob.Text & "',' " & txtemail.Text & " ','" & txtpp.Text & " ','" & txtpv.Text & " ',' " & txteno.Text & " ',' " & depcom.Text & " ', ' " & descom.Text & " ',' " & dtdoj.Text & " ','" & catcom.Text & "','" & mopcom.Text & "','" & txtac.Text & "','" & byes.Text & "',' " & txtbv.Text & "',' " & txtcdue.Text & "','" & txtcdate.Text & "','" & txtesino.Text & "','" & txtpfno.Text & "','" & expyes.Text & "',' " & detcom.Text & "','" & txtpc.Text & "','" & txtnc.Text & "' )"
              cmd = New OdbcCommand(str, con)
              cmd.ExecuteNonQuery()
              'check()
              MsgBox("Inserted")
              clear()
              con.Close()
          End Sub
      

      VIEW OPTION CODE

      con.Open()
              str = "select * from EmployeeMaster where Name='" & namecom.Text & "'"
              cmd = New OdbcCommand(str, con)
              dr = cmd.ExecuteReader
              If dr.Read Then
                  txtname.Text = dr.GetValue(0)
                  txtfname.Text = dr.GetValue(1)
                  dtdob.Text = dr.GetValue(2)
                  gencom.Text = dr.GetValue(3)
                  txtqual.Text = dr.GetValue(4)
                  txtbg.Text = dr.GetValue(5)
                  martcom.Text = dr.GetValue(6)
                  txtadd.Text = dr.GetValue(7)
                  txtcadd.Text = dr.GetValue(8)
                  txtpho.Text = dr.GetValue(9)
                  txtmob.Text = dr.GetValue(10)
                  txtemail.Text = dr.GetValue(11)
                  txtpp.Text = dr.GetValue(12)
                  txtpv.Text = dr.GetValue(13)
                  enocom.Text = dr.GetValue(14)
                  depcom.Text = dr.GetValue(15)
                  descom.Text = dr.GetValue(16)
                  dtdoj.Text = dr.GetValue(17)
                  catcom.Text = dr.GetValue(18)
                  mopcom.Text = dr.GetValue(19)
                  txtac.Text = dr.GetValue(20)
      
      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      rrrriiizz wrote:

      str = "Insert into EmployeeMaster values('" & txtname.Text & "','" & txtfname.Text & "','" & dtdob.Text & "','" & gencom.Text & "','" & txtqual.Text & " ','" & txtbg.Text & " ','" & martcom.Text & "','" & txtadd.Text & "',' " & txtcadd.Text & " ','" & txtpho.Text & "','" & txtmob.Text & "',' " & txtemail.Text & " ','" & txtpp.Text & " ','" & txtpv.Text & " ',' " & txteno.Text & " ',' " & depcom.Text & " ', ' " & descom.Text & " ',' " & dtdoj.Text & " ','" & catcom.Text & "','" & mopcom.Text & "','" & txtac.Text & "','" & byes.Text & "',' " & txtbv.Text & "',' " & txtcdue.Text & "','" & txtcdate.Text & "','" & txtesino.Text & "','" & txtpfno.Text & "','" & expyes.Text & "',' " & detcom.Text & "','" & txtpc.Text & "','" & txtnc.Text & "' )"

      This is begging for a SQL attack, you should use parameterised queries, or, better yet, stored procs. Colin has an excellent article on SQL injection, you should read it. In C#, you can do this: string sex = (rdoMale.Checked) ? "Male" : "Female"; Does VB do something like that ? Basically, it depends on how your data is stored, if it's a bool use the check result of the appropriate button. Otherwise, you need to build your paramater based on radio button state.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups