【发布时间】:2018-09-25 22:29:56
【问题描述】:
我正在设计一个计划器,但当我点击我的添加任务按钮时遇到了问题。单击它后,我的程序崩溃并显示此错误:
"System.Data.SqlClient.SqlException: '关键字'table'附近的语法不正确。'"
我在哪里可以找到不正确的语法?
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 InfoHub
{
public partial class Planner : Form
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\epoch\source\repos\InfoHub\InfoHub\planner.mdf;Integrated Security=True;Connect Timeout=30");
public Planner()
{
InitializeComponent();
}
private void Planner_Load(object sender, EventArgs e)
{
this.TopMost = true;
}
private void addTask_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into table values('" + textBox3.Text+"','"+textBox4.Text+"','"+textBox5.Text+"','"+textBox6.Text+"','"+textBox7.Text+"')";
cmd.ExecuteNonQuery();
con.Close();
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
}
【问题讨论】:
-
这个问题与标签、规划器或列表框无关,而与每次都使用 SQL 参数有关。永远。
-
我对你所说的这个可能的意思感到困惑,我应该从哪里开始使用这些参数?
标签: c# listbox listboxitem