与Sql相关的查询

本文关键字:查询 Sql | 更新日期: 2023-09-27 17:59:07

这个查询给了我一个错误"字符串"myCOnnection"后的未闭合quation标记如何解决它。

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);

与Sql相关的查询

您忘记在myConnection 前关闭插入查询后放置逗号

在查询后加逗号:

         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);

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

请参阅示例HERE