这是我写数据库操作类中的删除
public Boolean DeleteRecord(String tablename, string[] arParameters_where, Int32[] arParameters_Values_where)//删除记录
{
#region //执行Sql语句 Boolean ExecState = false;
OpenDB();
SqlCommand DBCommand = new SqlCommand();
string strSQL = "";
string strErorr = "";
strSQL = "Delete from " + tablename + "where "; int len1 = arParameters_where.Length; //获取最后一维的数组长度,这里是 3。
int len2 = arParameters_Values_where.Length;//
//"@" + arParameters_where[0] + "=" + arParameters_Values_where[0] + ")";
for (int i = 0; i < len1; i++)
{
strSQL += "@" + arParameters_where[i] + "=" + arParameters_Values_where[i];
}
strSQL=strSQL.Substring(0, strSQL.Length - 1);
try
{ DBCommand.Connection = DBConnection;
DBCommand.CommandText = strSQL; if (len1 > 0)
{
for (int i = 0; i < len1; i++)
{
SqlParameter parameter = new SqlParameter(arParameters_where[i], SqlDbType.VarChar);
parameter.Direction = ParameterDirection.Input;
parameter.Value = arParameters_Values_where[i];
DBCommand.Parameters.Add(parameter);
strErorr += arParameters_where[i] + " : " + arParameters_Values_where[i] + ";";
}
} if (DBCommand.ExecuteNonQuery() > 0)
{
ExecState = true;
} }
catch (SqlException Error)
{
ErrorMessage = Error.Message;
}
finally
{
CloseDB();
DBCommand.Dispose();
}
return ExecState;
#endregion在Webservice里写了一个deleteById方法调用DeleteRecord()方法
[WebMethod(Description = "删除一条记录")]
public Boolean deleteById(String tablename, string[] arParameters_where,Int32[] arParameters_Values_where)
{
return dbc.DeleteRecord(tablename, arParameters_where, arParameters_Values_where);
}
在客户端传参(根据id)进行删除操作为什么没反应啊
string[] arParameters_where = new string[1];
Int32[] arParameters_Values_where = new Int32[1];
arParameters_where[0] = "id"; arParameters_Values_where[0] = Convert.ToInt32(txtID.Text);
DialogResult dr = MessageBox.Show("是否删除数据", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
if (ss.deleteById("userinfo", arParameters_where, arParameters_Values_where) == true)
{
MessageBox.Show("删除成功");
}
this.BindDataGrid();
}
public Boolean DeleteRecord(String tablename, string[] arParameters_where, Int32[] arParameters_Values_where)//删除记录
{
#region //执行Sql语句 Boolean ExecState = false;
OpenDB();
SqlCommand DBCommand = new SqlCommand();
string strSQL = "";
string strErorr = "";
strSQL = "Delete from " + tablename + "where "; int len1 = arParameters_where.Length; //获取最后一维的数组长度,这里是 3。
int len2 = arParameters_Values_where.Length;//
//"@" + arParameters_where[0] + "=" + arParameters_Values_where[0] + ")";
for (int i = 0; i < len1; i++)
{
strSQL += "@" + arParameters_where[i] + "=" + arParameters_Values_where[i];
}
strSQL=strSQL.Substring(0, strSQL.Length - 1);
try
{ DBCommand.Connection = DBConnection;
DBCommand.CommandText = strSQL; if (len1 > 0)
{
for (int i = 0; i < len1; i++)
{
SqlParameter parameter = new SqlParameter(arParameters_where[i], SqlDbType.VarChar);
parameter.Direction = ParameterDirection.Input;
parameter.Value = arParameters_Values_where[i];
DBCommand.Parameters.Add(parameter);
strErorr += arParameters_where[i] + " : " + arParameters_Values_where[i] + ";";
}
} if (DBCommand.ExecuteNonQuery() > 0)
{
ExecState = true;
} }
catch (SqlException Error)
{
ErrorMessage = Error.Message;
}
finally
{
CloseDB();
DBCommand.Dispose();
}
return ExecState;
#endregion在Webservice里写了一个deleteById方法调用DeleteRecord()方法
[WebMethod(Description = "删除一条记录")]
public Boolean deleteById(String tablename, string[] arParameters_where,Int32[] arParameters_Values_where)
{
return dbc.DeleteRecord(tablename, arParameters_where, arParameters_Values_where);
}
在客户端传参(根据id)进行删除操作为什么没反应啊
string[] arParameters_where = new string[1];
Int32[] arParameters_Values_where = new Int32[1];
arParameters_where[0] = "id"; arParameters_Values_where[0] = Convert.ToInt32(txtID.Text);
DialogResult dr = MessageBox.Show("是否删除数据", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
if (ss.deleteById("userinfo", arParameters_where, arParameters_Values_where) == true)
{
MessageBox.Show("删除成功");
}
this.BindDataGrid();
}
你生成的语句是上面的吗?~~
=====================
strSQL += "@" + arParameters_where[i] + "='" + arParameters_Values_where[i] + "'";
没执行 还是不知道改哪
你用的是SQLSERVER 企业版就会有个事件探查器,也就是profile ,打开后选择目标服务器,输入用户名,密码等选择跟踪项等,
成功连接后你自己会看到一些东西的,不再废话了
如果你用的是SQL SERVER 2005 EXPRESS 就没有这个时间探查器,你可以在去下载一个SqlExpressProfiler的工具安装完毕后实现上述功能。