源码如下:
Dao层 SqlHelper.cs:
public class SqlHelper
{
public static int ExecuteNonQuery(string sql, params SqlParameter[] parameters)
{
String connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
foreach (SqlParameter parameter in parameters)
{
cmd.Parameters.Add(parameter);
}
return cmd.ExecuteNonQuery();
}
}
服务层 Service.cs :
public static int dataUpdate(int i,params Object[] o)
{
String strsql = "Update Device set TName = @TName Where Id = @Id ";
SqlHelper.ExecuteNonQuery(strsql,
new SqlParameter("@Id", i),
new SqlParameter("@TName", o[0]));
int result = SqlHelper.ExecuteNonQuery(strsql);
return result;
}
主窗体按钮:
private void btnUpdate_Click(object sender, EventArgs e)
{
MessageBox.Show(pdtp.Value.ToString("yyyy/MM/dd"));
Service.dataUpdate(
Convert.ToInt32(textBox1.Text),
NameText.Text
);
}
服务层的内容使用Insert就没问题,为什么update就报错了?