title: Error converting data type varchar to numeric in c# program
body: <p>Please Help me out,This is my database table in sql-server</p>
  
  <pre><code>(empcode    varchar(50)
  firstname   varchar(50)
  lastname    varchar(50)
  gender  varchar(50)
  address varchar(50)
  contactno   numeric(18, 0)
  bloodgroup  varchar(50)
  dateofbirth date
  country varchar(50)
  qid varchar(50)
  passportno  varchar(50)
  passportexpiredate  date
  designation varchar(50)
  doj date    
  doexpid date
  pf_acc_no   numeric(18, 0)  
  agreementstartdate  date    
  agreementenddate    date    
  department  varchar(50) 
  basic_sal   numeric(18, 0)  
  remarks varchar(50) 
  empimage    image)
  </code></pre>
  
  <p>and I'm Trying to insert my data through c# windows forms but i'm getting error as "<strong>Error converting data type varchar to numeric.</strong>"
  Here below is my c# code</p>
  
  <pre><code>private void button2_Click(object sender, EventArgs e)
      {
          cn.Open();
          if (!empid())
          {
              DialogResult d = new DialogResult();
              d = MessageBox.Show("Do You Declare Yourself All The Information Of This Employee Is Correct To Save?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
              if (d == DialogResult.Yes)
              {
                  int i = 0;
                  SqlCommand cmd = new SqlCommand("INSERT INTO Employee(
       empcode,firstname,lastname,gender,address,contactno,bloodgroup,
      dateofbirth, country,qid,passportno,passportexpiredate,designation,
      doj,doexpid,pf_acc_no, agreementstartdate,agreementenddate,
      department,basic_sal,remarks,empimage) 
      VALUES('" + txtempcode.Text + "','" + txtfrstname.Text + "', 
      '" + txtlstname.Text + "','" + combogender.Text + "','" +
      txtaddr.Text + "','" + txtcont.Text + "','" + txtblodgrp.Text + "', '" + 
      dob.Value.ToString("yyyy/MM/dd") + "' ,'" + txtcountry.Text + "','" + tqid.Text + "','" + 
      txtpassportno.Text + "', '" + passexpdate.Value.ToString("yyyy/MM/dd") + "' ,'" + 
      combodesig.Text + "', '" + doj.Value.ToString("yyyy/MM/dd") + "', '" + doexpqid.Value.ToString("yyyy/MM/dd") + "', '" + 
      txtqibacc.Text + "', '" + agreestartdate.Value.ToString("yyyy/MM/dd") + "','" + agreeenddate.Value.ToString("yyyy/MM/dd") + "' ,'" + combobranch.Text + "','" + txtnetsalary.Text + "','" + txtremark.Text + "',@empimage) ", cn);
  
                      MemoryStream stream = new MemoryStream();
                      pb1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                      byte[] pic = stream.ToArray();
                      cmd.Parameters.AddWithValue("@empimage", pic);
                  i = cmd.ExecuteNonQuery();
  
                  if (i &gt; 0)
                  {
                      MessageBox.Show("Successfully Inserted Employee Record" + i);
                  }
                  cn.Close();
                  showdata();
                  clear();
              }
          }
      }
  
  public bool empid()
      {
          using (SqlConnection con = new SqlConnection("Data Source=SAFIYA-PC;Initial Catalog=dbEmployee;User ID=sa;Password=sa$123"))
          {
              con.Open();
              string query = "select empcode from Employee where empcode = '" + txtempcode.Text + "'";
              SqlCommand cmd = new SqlCommand(query, con);
              SqlDataReader dr;
              dr = cmd.ExecuteReader();
              while (dr.Read())
              {
                  empCode = dr["empcode"].ToString();
                  if (empCode != "0")
                  {
                      MessageBox.Show("Id already Existed Please use Another One!!!!!!");
                      return false;
                  }
                  con.Close();
              }
              return true;
          }                        
      }
  </code></pre>