Jayita Roy

Jayita Roy

  • NA
  • 22
  • 3.6k

Can't understand where I am wrong! Please help

Jun 16 2015 12:54 PM
SqlConnection con1 = new SqlConnection("Data Source=JAYI-PC\\SQLEXPRESS;Initial Catalog=db-ub;Integrated Security=True");
con1.Open();
Image img = pictureBox_UB.Image;
byte[] arr;
ImageConverter converter = new ImageConverter();
arr = (byte[])converter.ConvertTo(img, typeof(byte[]));
//SqlCommand cmd1 = new SqlCommand("Insert into Visitors (Image) values('"+arr+"')");
//cmd1.ExecuteNonQuery();

string s = "";
if (comboBox_TOWHOM.SelectedIndex >= 0)
s = comboBox_TOWHOM.Items[comboBox_TOWHOM.SelectedIndex].ToString();

string c = "";
if (comboBox_color.SelectedIndex >= 0)
c = comboBox_color.Items[comboBox_color.SelectedIndex].ToString();

string n = "";
if(numericUpDown_Person.Value >= 0)
n = numericUpDown_Person.Value.ToString();

string prps = string.Empty;
if(radioButton_OFFICIAL.Checked)
{
prps = "Official";
}
else if(radioButton_PERSONAL.Checked)
{
prps = "Personal";
}

SqlCommand cmd1 = new SqlCommand("Insert into Visitors(Id,Visitor Name,Organisation Name,Phone No,No of Person,Whom to Visit,Purpose,Color Code,Day In,Time In, Image)values("+textBox_Id.Text+",'" + textBox_NameV.Text + "','" + textBox_Org.Text + "'," + textBox_Phn.Text + ",'" + n + "','" + s + "','" + prps + "','" + c + "','" + textBox_Dayin.Text + "','" + textBox_timeR.Text + "'," + arr + ")",con1);
cmd1.ExecuteNonQuery();
MessageBox.Show("Record has been inserted");
con1.Close();


Answers (9)