虽然成功运行编译后的代码错误,我有错误的关键字“终结”近C#上运行的代码
不正确的语法。
尽管代码格式良好但出现错误。 有人请帮我解决问题。我的代码在下面;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Order
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlConnection ABC = new SqlConnection(@"Data Source=iPC\SQLEXPRESS;Initial Catalog=NML;Integrated Security=True");
SqlCommand command = new SqlCommand();
//SqlDataReader dataRead = new SqlDataReader();
private void button1_Click(object sender, EventArgs e)
{
ABC.Open();
command.CommandText = "INSERT INTO tbl_REC(Qcode,Warp,Ply,Blend,TEnds,Warp1,Weft,End,Pick,,Width,Weave1,Weave2,TL) Values('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "','" + textBox11.Text + "','" + textBox12.Text + "','" + textBox13.Text + "','" + textBox14.Text + "')";
command.Connection = ABC;
command.ExecuteNonQuery();
ABC.Close();
MessageBox.Show("DATA SAVED SUCCESSFULLY");
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox10.Clear();
textBox11.Clear();
textBox12.Clear();
textBox13.Clear();
textBox14.Clear();
dateTimePicker1.Value = DateTime.Now;
}
private void Form2_Load(object sender, EventArgs e)
{
command.Connection = ABC;
}
}
}
了解传递值到查询时使用的参数。篡改查询字符串可能会导致无法解释的语法错误 - 并使代码容易受到SQL注入攻击。 –