作者:从容面对天下事 | 来源:互联网 | 2023-08-11 12:49
string myKeyid="";
string myCOnnString="server=localhost;uid=sa;pwd=candywen;database=sg1";
SqlConnection myConnection = new SqlConnection(myConnString);
SqlCommand sqlCmd=new SqlCommand("DEL_MSG",myConnection);
sqlCmd.CommandType =CommandType.StoredProcedure;
sqlCmd.CommandText ="DEL_MSG";
SqlParameter AddKeyid = new SqlParameter("@MsgIDS",SqlDbType.VarChar,16);
AddKeyid.Value= myKeyid;
;
for(int i=0;i
{
CheckBox cb=(CheckBox)dgMsgList.Items[i].Cells[0].Controls[1];
if(cb.Checked)
{
//Response.Write("");
myKeyid = this.dgMsgList.DataKeys[i].ToString();
sqlCmd.Parameters.Add(AddKeyid);
}
}
try
{
myConnection.Open();
sqlCmd.ExecuteNonQuery();
myConnection.Close();
}
10 个解决方案
没看懂,是这样么?
string myCOnnString="server=localhost;uid=sa;pwd=candywen;database=sg1";
SqlConnection myConnection = new SqlConnection(myConnString);
SqlCommand sqlCmd=new SqlCommand("DEL_MSG",myConnection);
sqlCmd.CommandType =CommandType.StoredProcedure;
sqlCmd.CommandText ="DEL_MSG";
SqlParameter AddKeyid = new SqlParameter("@MsgIDS",SqlDbType.VarChar,16);
sqlCmd.Parameters.Add(AddKeyid);
try
{
myConnection.Open();
for(int i=0;i {
CheckBox cb=(CheckBox)dgMsgList.Items[i].Cells[0].Controls[1];
if(cb.Checked)
{
//Response.Write("");
AddKeyid.Value= this.dgMsgList.DataKeys[i].ToString();
sqlCmd.ExecuteNonQuery();
}
}
}
finally
{
if (myConnection != null);
myConnection.Close();
}
string myCOnnString="server=localhost;uid=sa;pwd=candywen;database=sg1";
SqlConnection myConnection = new SqlConnection(myConnString);
SqlCommand sqlCmd=new SqlCommand("DEL_MSG",myConnection);
sqlCmd.CommandType =CommandType.StoredProcedure;
sqlCmd.CommandText ="DEL_MSG";
try
{
myConnection.Open();
for(int i=0;i {
CheckBox cb=(CheckBox)dgMsgList.Items[i].Cells[0].Controls[1];
AddKeyid.Value= this.dgMsgList.DataKeys[i].ToString();
SqlParameter AddKeyid = new SqlParameter,SqlDbType.VarChar,16);
sqlCmd.Parameters.Add(AddKeyid);
}
sqlCmd.ExecuteNonQuery();
}
}
finally
{
if (myConnection != null);
myConnection.Close();
}
你真想一次运行的话,大概应该这么试
using Systme.Text;
StringBuilder sb = new StringBuilder();
for(int i=0;i {
CheckBox cb=(CheckBox)dgMsgList.Items[i].Cells[0].Controls[1];
if(cb.Checked)
{
sb.AppendFormat("DEL_MSG '{0}'; ", this.dgMsgList.DataKeys[i].ToString().Replace("'","''"));
}
}
if (sb.Length > 0)
{
string myCOnnString="server=localhost;uid=sa;pwd=candywen;database=sg1";
SqlConnection myConnection = new SqlConnection(myConnString);
SqlCommand sqlCmd=new SqlCommand(sb.ToString(),myConnection);
try
{
myConnection.Open();
sqlCmd.ExecuteNonQuery();
}
finally
{
if (myConnection != null);
myConnection.Close();
}
}
第 1 行: 'DEL_MSG' 附近有语法错误。
try
sb.AppendFormat("exec DEL_MSG '{0}'; ", this.dgMsgList.DataKeys[i].ToString().Replace("'","''"));