执行存储过程的问题?

ligaru 2004-10-14 02:26:11
CREATE PROCEDURE User_leave
/*在职(离职)用户*/
@User_INTs varchar(500), /*被复职的员工ID集合*/
@User_leave bit /*在离职标志*/

AS
EXEC ('UPDATE Th_User SET User_leave =@User_leave WHERE User_INT IN (' + @User_INTs + ')')
GO

执行该存储过程的代码如下:
public bool User_leave(string User_INTs,int User_leave)
{
//调用存储过程 User_leave 参数为:用户登录ID和在职标志
string my_User_leave = "User_leave '"+User_INTs+"',"+User_leave+"";
if (ConnectDB(strDS,strDB,strUser,strPwd) == true)//myConnection.Open()
{
SqlCommand myCommand = new SqlCommand(my_User_leave,myConnection);
try
{
myCommand.ExecuteNonQuery();
myConnection.Close();
return true;
}//try
catch (SqlException myException)
{
SqlErrorCollection myErrors = myException.Errors;

for (int i=0; i < myErrors.Count; i++)
{
myErrorString = "Index #" + i + "\n" +
"Error: " + myErrors[i].ToString() + "\n";
}
return false;
}//catch

}
else
{
return false;
}
}
为什么上面的代码执行不了存储过程?
...全文
111 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gaoxiaospring 2004-10-15
  • 打赏
  • 举报
回复
上面的多打了一行.另外,请不要把 SqlConnection.Close()放到Try中。

public bool User_leave(string User_INTs,int User_leave)
{

if (ConnectDB(strDS,strDB,strUser,strPwd) == true)//myConnection.Open()
{
//SqlCommand myCommand = new SqlCommand();//多了

SqlCommand myCommand=new SqlCommand();
myCommand.Connection=myConnection;
myCommand.CommandText="User_leave";
myCommand.CommandType=CommandType.StoredProcedure ;
myCommand.Parameters.Add("@User_INTs",User_INTs);
myCommand.Parameters.Add("@User_leave",User_leave);

try
{
myCommand.ExecuteNonQuery();
//...
}
}
gaoxiaospring 2004-10-15
  • 打赏
  • 举报
回复
public bool User_leave(string User_INTs,int User_leave)
{

if (ConnectDB(strDS,strDB,strUser,strPwd) == true)//myConnection.Open()
{
SqlCommand myCommand = new SqlCommand();

SqlCommand myCommand=new SqlCommand();
myCommand.Connection=myConnection;
myCommand.CommandText="User_leave";
myCommand.CommandType=CommandType.StoredProcedure ;
myCommand.Parameters.Add("@User_INTs",User_INTs);
myCommand.Parameters.Add("@User_leave",User_leave);

try
{
myCommand.ExecuteNonQuery();
//...
}
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧