private void button2_Click(object sender, EventArgs e)
{
string DonorType = "";
string DonatedBlood = "";
string VoluntaryDonor = "";
string DonationPeriod = "";
if (txtrid.Text == "" || txtrid.Text == null)
MessageBox.Show("Please enter Registration Id");
else
{
if (txtrid.Text != "" && txtfname.Text != "" && txtlname.Text != "" && txtage.Text != "" && txtadd.Text != "" && txttno.Text != "")
{
if (rdBtnVoluntary.Checked)
DonorType = "Voluntary";
else if (rdBtnReplacement.Checked)
DonorType = "Replacement";
else if (rdBtnAuto.Checked)
DonorType = "AutoLogus";
else if (rdBtnDirect.Checked)
DonorType = "Direct";
if (radBtnDonatedYes.Checked)
DonatedBlood = "Yes";
else if (radBtnDonatedNo.Checked)
DonorType = "No";
if (rdBtnVoluntaryYes.Checked)
VoluntaryDonor = "Yes";
else if (rdBtnVoluntaryNo.Checked)
VoluntaryDonor = "No";
if (rdBtn3M.Checked)
DonationPeriod = "3M";
else if (rdBtn6M.Checked)
DonationPeriod = "6M";
else if (rdBtn12M.Checked)
DonationPeriod = "12M";
}
}
SqlConnection cn = new SqlConnection(@"Data Source=DARSHAN-PC\SQLEXPRESS;Initial Catalog=BBMS;Integrated Security=True");
SqlDataReader dr;
cn.Open();
string sQuery = "insert into reg_details(registration_id,first_name,middle_name,last_name,age,donor_address,telephone_number,mobile_number,date,occupation,blood_group,patient_name,ward,gender,last_date_of_donation) values('" + txtrid.Text + "','" + txtfname.Text + "','" + txtmname.Text + "','" + txtlname.Text + "','" + txtage.Text + "','" + txtadd.Text + "','" + txttno.Text + "','" + txtmno.Text + "','" + txtdate.Text + "','" + txtocc.Text + "','" + comboBox1.Text + "','" + txtpname.Text + "','" + txtward.Text + "','" + comboBox2.Text + "','" + txtldd.Text + "')";
SqlCommand cmd = new SqlCommand(sQuery);
cmd.Connection = cn;
try {
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw ex;
}
finally
{
cn.Close();
}
MessageBox.Show("inserted");
}
is the code for radio button correct?
the error is: cannot put value null to column donor type,table 'BBMS.dbo/reg_details';columns does not allow nulls.INSERT fails.

New Topic/Question
Reply



MultiQuote





|