form.CS
private void button1_Click(object sender, EventArgs e)
{
object i= SQLHelper.ExecuteNonQuery("Insert into T_Ps(Name,Age) values(@Name,@Age)",new
SqlParameter("Name","Tom"),new SqlParameter("Age",30));
MessageBox.Show(Convert.ToString(i));
}
ExecuteNonQuery
public static int ExecuteNonQuery(string sql, params SqlParameter[] parameters)
{
string conStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(conStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
foreach (SqlParameter parameter in parameters)
{
cmd.Parameters.Add(parameter);
}
return cmd.ExecuteNonQuery();
}
}
其他地方写的也一样,对数据库查询都是能查出来的,就是对数据库里更改等操作就不行了,也不报错,新手不懂,求教。。