请问在C#中如何调用存储过程?那个存储过程有select,update操作,不传递参数给存储过程的,大家给一段事例代码呀?小的感激不尽! 

解决方案 »

  1.   

    好复杂的这是微软的例子
    public void CreateMySqlCommand(string myExecuteQuery, SqlConnection myConnection) 
     {
        SqlCommand myCommand = new SqlCommand(myExecuteQuery, myConnection);
        myCommand.Connection.Open();
        myCommand.ExecuteNonQuery();
        myConnection.Close();
     }
    myExecuteQuery就是你的存储过程名字
    myConnection就是连接数据库方法
    这里访问的数据库是sql server
      

  2.   

    /*
    create proc p_xxx
    as
    begin
      select ...
      update ...
    end
    go
    */
    using System.Data.SqlClient;
    ...
    SqlConnection cn = new SqlConnection("....");
    cn.Open();
    SqlCommand cmd = new SqlCommand("p_xxx", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.ExecuteNonQuery();
    ...
      

  3.   

    cmd.CommandType = CommandType.StoredProcedure;
    这一句一定要写啊