public string connection()
{
string connstr;
connstr = ConfigurationManager.AppSettings[ "databasestr "].ToString();
return connstr;
}
public void cmd(string sqlstr)
{
try
{
SqlCommand cmd = new SqlCommand(sqlstr, connection());
cmd.ExecuteNonQuery(CommandBehavior.CloseConnection);//就这里提示出错信息
}
catch
{
HttpContext.Current.Response.Write( "提示:操作没有被完成!请与管理员联系!错误号: <b> CMD </b> ");
HttpContext.Current.Response.End();
}
}
提示这个:“ExecuteNonQuery”方法没有采用“1”个参数的重载
------解决方案--------------------------------------------------------
ExecuteNonQuery()方法没有参数的,不能加CommandBehavior.CloseConnection
------解决方案--------------------------------------------------------
你这里哪里有SqlConnection?咋没看见?
------解决方案--------------------------------------------------------
说的很清楚了
ExecuteNonQuery”方法没有采用“1”个参数的重载
------解决方案--------------------------------------------------------
private SqlConnection connection()
{
string connstr;
connstr = ConfigurationManager.AppSettings[ "databasestr "].ToString();
SqlConnection con = new SqlConnection(connstr);
return con;
}
SqlConnection con = connection();
SqlCommand cmd = new SqlCommand(sqlstr, con);
然后con.close()
------解决方案--------------------------------------------------------
ExecuteNonQuery没有参数.
------解决方案--------------------------------------------------------
声明一个conn,然后关闭
------解决方案--------------------------------------------------------
改成cmd.ExecuteNonQuery();