与Sql相关的查询

时间:2014-04-21 11:58:11

标签: c# sql

此查询在字符串" myCOnnection"之后给我一个错误"未闭合的引号如何解决它。

INSERT INTO Company_Master
(C_Name,M_Name,L_No,Tax_No,PO_No,Location,State,Country,Telephone,Fax_No,Email_Id,
Website,Currency_Name,Company_logo,APT,APF) VALUES('" + textBox1.Text + "', '" + 
textBox2.Text +"','" + textBox3.Text + "','" + textBox4.Text + "','" + 
textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + 
textBox8.Text + "','" + textBox9.Text + "','" +textBox10.Text+"','"+ 
textBox11.Text+"','"+textBox12.Text+"','"+textBox13.Text+"','" + 
pictureBox1.Image+"','" + dateTimePicker1.Value+"','"+dateTimePicker2.Value+"')" 
myConnection);

2 个答案:

答案 0 :(得分:4)

在myConnection

之前关闭插入查询后忘记输入逗号

答案 1 :(得分:4)

查询后输入逗号:

         string query="INSERT INTO Company_Master
         (C_Name,
          M_Name,
          L_No,
          Tax_No,
          PO_No,
          Location,
          State,
          Country,
          Telephone,
          Fax_No,
          Email_Id,
          Website,
          Currency_Name,
          Company_logo,
          APT,APF) 
  VALUES('" + textBox1.Text + "',
         '" + textBox2.Text + "',
         '" + textBox3.Text + "',
         '" + textBox4.Text + "',
         '" + textBox5.Text + "',
         '" + textBox6.Text + "',
         '" + textBox7.Text + "',
         '" + textBox8.Text + "',
         '" + textBox9.Text + "',
         '" +textBox10.Text+"',
         '"+ textBox11.Text+"',
         '"+textBox12.Text+"',
         '"+textBox13.Text+"',
         '" + pictureBox1.Image+"',
         '" + dateTimePicker1.Value+"',
         '"+dateTimePicker2.Value+"')";

 SqlCommand cmd = new SqlCommand(query, myConnection);

这不是一个好方法,总是使用参数化查询。

请参阅Example HERE