the code works fine.. but when i look inside my tblstudent in my db, the text "System.Windows.Forms.TextBox, Text:" is automatically inserting to some of my fields..
for ex: mobile: 09xxxxxxx
"System.Windows.Forms.TextBox, Text: 09xxxxxxx" in my dbtable..
What I have tried:
SqlConnection cnn = new SqlConnection(cs.constring());
SqlDataAdapter adapter = new SqlDataAdapter();
string sql = "insert into tblstudent (sno,s_name,gender,age,birthday,civil_status,place_of_birth,address,citizenship,religion,blood_type,mobile,telephone,email,father,f_occupation,mother,m_occupation,guardian,g_relationship,g_address,g_mobile,admission_date) values('" + txtsno.Text + "','" +
txtname.Text + "','" + cbogender.Text + "','" + txtage.Text + "','" + dtpbirthday.Text + "','" + cbostatus.Text + "','" + txtplaceofbirth.Text + "','" + txtaddress.Text + "','" + txtcitizenship.Text + "','" + txtreligion.Text + "','" + txtbloodtype.Text + "','" + txtmobile + "','" +
txttel.Text + "','" + txtemail.Text + "','" + txtfather.Text + "','" + txtfoccupation.Text + "','" + txtmother.Text + "','" + txtmoccupation + "','" + txtguardian.Text + "','" + txtrelationship.Text + "','" + txtgaddress + "','" + txtgmobile.Text + "','" + dtpadmission.Text + "')";
if (MessageBox.Show("do you want to save?", "choose an option", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
cnn.Open();
adapter.InsertCommand = new SqlCommand(sql, cnn);
adapter.InsertCommand.ExecuteNonQuery();
MessageBox.Show("record saved !! ");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
}