radio button in windows form..urgt plzz..
-
i made a form of student registration. here i create two radio buttons against gender (Male,Female), and create database connectivity of these two buttons, now when i click on radio button for male or female it gives me error that "number of query values and destination fields are not the same". how the entries of radio button goes in databse plz tell me. i'm so worried following is my code which use for database connectivity of radio buttons. ------------------------------------------------------------------------ OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\db1.mdb;Persist Security Info=False");//("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\SMSDB.mdb;Persist Security Info=False"); con.Open(); string idata = "insert into db1 values('"+txtID.Text+"','"+rbmale.Text+"','"+rbfemale.Text+"')"; OleDbTransaction tx = con.BeginTransaction(); tx.Commit(); OleDbCommand cmd = new OleDbCommand(idata,con); cmd.ExecuteNonQuery(); con.Close(); ------------------------------------------------------------------------- m.reehanmunir
-
i made a form of student registration. here i create two radio buttons against gender (Male,Female), and create database connectivity of these two buttons, now when i click on radio button for male or female it gives me error that "number of query values and destination fields are not the same". how the entries of radio button goes in databse plz tell me. i'm so worried following is my code which use for database connectivity of radio buttons. ------------------------------------------------------------------------ OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\db1.mdb;Persist Security Info=False");//("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\SMSDB.mdb;Persist Security Info=False"); con.Open(); string idata = "insert into db1 values('"+txtID.Text+"','"+rbmale.Text+"','"+rbfemale.Text+"')"; OleDbTransaction tx = con.BeginTransaction(); tx.Commit(); OleDbCommand cmd = new OleDbCommand(idata,con); cmd.ExecuteNonQuery(); con.Close(); ------------------------------------------------------------------------- m.reehanmunir
r_e_h_a_n wrote:
string idata = "insert into db1 values('"+txtID.Text+"','"+rbmale.Text+"','"+rbfemale.Text+"')";
Well, your approach to database development will never scale to real world apps, but I guess it's fine for now. You're passing the text of both radio buttons to the database. It does not surprise me that you don't have three fields to save against. You probably want something like this: string idata = "insert into db1 values('"+txtID.Text+"','" + rbmale.Checked ? "M" " "F"+"')"; This stores M or F, depending on if rbMale is checked or not. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
i made a form of student registration. here i create two radio buttons against gender (Male,Female), and create database connectivity of these two buttons, now when i click on radio button for male or female it gives me error that "number of query values and destination fields are not the same". how the entries of radio button goes in databse plz tell me. i'm so worried following is my code which use for database connectivity of radio buttons. ------------------------------------------------------------------------ OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\db1.mdb;Persist Security Info=False");//("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\SMSDB.mdb;Persist Security Info=False"); con.Open(); string idata = "insert into db1 values('"+txtID.Text+"','"+rbmale.Text+"','"+rbfemale.Text+"')"; OleDbTransaction tx = con.BeginTransaction(); tx.Commit(); OleDbCommand cmd = new OleDbCommand(idata,con); cmd.ExecuteNonQuery(); con.Close(); ------------------------------------------------------------------------- m.reehanmunir
Dear Reehan Bhai, Please change your Insert query as following: String idata="Insert into db1 values("+txtID.Text+","+(rbmale.Checked ? rbmale.Text:tbfemale.Text+")"; I think above query must solve your problem. Regards, Wasif Ehsan