关于使用C#向access数据库表update数据时的一个问题!
此为我代码:privatestaticvoidUpdateBase(doublekafang,stringword,stringbasePath){stringconns...
此为我代码:
private static void UpdateBase(double kafang, string word, string basePath)
{
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + basePath;
using (OleDbConnection conn = new OleDbConnection(connstr))
{
try
{
conn.Open();
string sql = @"UPDATE WORDCOUNT1 SET [KAFANG] = " + kafang + " WHERE WORD = " + word;
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine("异常:" + ex.Message);
}
}
}
数据库字段格式:
调试一直显示,至少一个参数没有被指定值,请问错在哪里? 展开
private static void UpdateBase(double kafang, string word, string basePath)
{
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + basePath;
using (OleDbConnection conn = new OleDbConnection(connstr))
{
try
{
conn.Open();
string sql = @"UPDATE WORDCOUNT1 SET [KAFANG] = " + kafang + " WHERE WORD = " + word;
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine("异常:" + ex.Message);
}
}
}
数据库字段格式:
调试一直显示,至少一个参数没有被指定值,请问错在哪里? 展开
1个回答
展开全部
conn.Open();
//Access SQL 用?表示参数
string sql = @"UPDATE WORDCOUNT1 SET [KAFANG] =? WHERE WORD=?";
OleDbCommand cmd = new OleDbCommand(sql, conn);
//为第一个参数赋值
OleDbParameter p1 =cmd.Parameters.Add("para1", OleDbType.Double);
p1.Value = kafang;
//为第二个参数赋值
OleDbParameter p2 =cmd.Parameters.Add("para2", OleDbType.VarWChar);
p2.Value = word;
//执行
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询