我是 C# 新手,正在尝试将东西插入 SQL Server CE 数据库。我不明白为什么这段代码不起作用。我得到一个
System.Data.SqlServerCE.SqlCeException
com1.ExecuteNonQuery();
程序运行时指向该行的错误。
我附上了我用来插入表格的代码。
//Connecting to SQL Server
SqlCeConnection conn1 = new SqlCeConnection();
conn1.ConnectionString = connection; //connection is a string variable which has the connection details
conn1.Open();
SqlCeCommand com1 = new SqlCeCommand();
com1.Connection = conn1;
com1.CommandType = CommandType.Text;
com1.CommandText = "INSERT into data(pname, budget, dcommision, advance, phone, cdetails, mail) values(@pname , @budget, @dcommision, @advance, @phone, @cdetails, @mail)";
com1.Parameters.AddWithValue("@pname", textBox8.Text.Trim());
com1.Parameters.AddWithValue("@budget", budget);
com1.Parameters.AddWithValue("@dcommision", textBox7.Text.Trim());
com1.Parameters.AddWithValue("@advance", advance);
com1.Parameters.AddWithValue("@phone", phone);
com1.Parameters.AddWithValue("@cdetails", richTextBox1.Text.Trim());
com1.Parameters.AddWithValue("@mail", textBox3.Text.Trim());
com1.ExecuteNonQuery(); //Executing the SQL query
com1.Dispose(); //Closing SQL Server connection
conn1.Close();
我的查询有问题吗?我真的是一个新手,所以非常感谢一些帮助。谢谢