[英]Cannot insert the data into the table using C# visual studio 2008
[英]cannot insert data into access using c#
我尝试了很多次,但是数据无法插入但没有错误
请帮忙
public static void SaveCorresDetails(string cN, string cId, string pId, string rI)
{
OleDbConnection myConnection = GetConnection();
string myQuery = "INSERT INTO RAHANICorrespondent(DateIssue, Action, Recipient, Remarks) VALUES ( '" + cN + "' , '" + cId + "', '" + pId + "','" + rI + "')";
OleDbCommand myCommand = new OleDbCommand(myQuery, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Exception in DBHandler", ex);
}
finally
{
myConnection.Close();
}
}
这将是添加数据的类文件
protected void Button1_Click(object sender, EventArgs e)
{
string n = TextBox1.Text.Trim();
string c = TextBox2.Text.Trim();
string p = TextBox3.Text.Trim();
string r = TextBox4.Text.Trim();
// save the data into the database
Data.SaveCorresDetails(n, c, p, r);
Label6.Text = "Package amount of " + n + " was saved";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
谢谢...
尝试改用db参数。
OleDbConnection connection = new OleDbConnection(""); string query = "INSERT INTO myTable (a,b,c) Values(@a, @b @c)"; OleDbParameter param = new OleDbParameter("a", "Hi man"); param.DbType = ... OleDbCommand command = new OleDbCommand(query); command.CommandType = System.Data.CommandType.Text; int result = command.ExecuteNonQuery();
然后检查是否收到错误并记录下来,看看是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.