指定:
SelectCommand1.CommandType = CommandType.StoredProcedure;

解决方案 »

  1.   

    我的项目中的一个方法: public int addList(int ListType,string RefID, string UserID)
    {
    int ListID;
    ListID = 0; SqlConnection connFaq = new SqlConnection(this.connection);

    SqlCommand cmdAddList = new SqlCommand("faq_list_insert",connFaq);
    cmdAddList.CommandType = CommandType.StoredProcedure;
    SqlParameter prmListType = new SqlParameter("@ListType", SqlDbType.TinyInt,0);
    prmListType.Direction = ParameterDirection.Input;
    cmdAddList.Parameters.Add(prmListType);
    prmListType.Value =  ListType;

    SqlParameter prmRefID = new SqlParameter("@RefID", SqlDbType.NVarChar, 50);
    prmRefID.Direction = ParameterDirection.Input;
    cmdAddList.Parameters.Add(prmRefID);
    prmRefID.Value =  RefID; SqlParameter prmUserID = new SqlParameter("@UserID", SqlDbType.NVarChar, 20);
    prmUserID.Direction = ParameterDirection.Input;
    cmdAddList.Parameters.Add(prmUserID);
    prmUserID.Value =  UserID;
    SqlParameter prmListID = new SqlParameter("@ListID", SqlDbType.Int,0);
    prmListID.Direction = ParameterDirection.Output;
    cmdAddList.Parameters.Add(prmListID);
    prmListID.Value =  ListID;
    connFaq.Open(); cmdAddList.ExecuteNonQuery(); connFaq.Close(); return (int)prmListID.Value;

    }
      

  2.   

    我有一个,可以取出存储过程的output和return。public class dealbudget
    {
    public dealbudget()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }

    public string ReturnValue;
    public void GetResult(string StockCode,string ExCode,string BsFlag, decimal NewPrice)
    {
    //=========================调用pr_budget存储过程===========================
    String strConn;
    SqlConnection cn;
    strConn = ConfigurationSettings.AppSettings["stock"];
    // 连接到stock数据库
    cn = new SqlConnection(strConn);
    SqlCommand cm = new SqlCommand("",cn);
    cn.Open();
    cm.CommandText="pr_budget";
    cm.CommandType =CommandType.StoredProcedure;
    cm.Parameters.Add(new SqlParameter("@p_userid",SqlDbType.Int,20)); //用户id
    cm.Parameters.Add(new SqlParameter("@p_stockcode",SqlDbType.VarChar,6)); //股票代码
    cm.Parameters.Add(new SqlParameter("@p_excode",SqlDbType.VarChar,6)); //证交所代码
    cm.Parameters.Add(new SqlParameter("@p_bsflag",SqlDbType.VarChar,6)); //买卖标志
    cm.Parameters.Add(new SqlParameter("@p_newprice",SqlDbType.Decimal)); //最新价
    cm.Parameters.Add(new SqlParameter("@p_freecp",SqlDbType.Decimal,14,ParameterDirection.Output,false,0,0,string.Empty,  DataRowVersion.Default, null)); //可用资金
    cm.Parameters.Add(new SqlParameter("@p_canbuy",SqlDbType.Decimal,14,ParameterDirection.Output,false,0,0,string.Empty,  DataRowVersion.Default, null)); //可买股票数
    cm.Parameters.Add(new SqlParameter("@p_cansell",SqlDbType.Decimal,14,ParameterDirection.Output,false,0,0,string.Empty,  DataRowVersion.Default, null)); //可卖股票数
    cm.Parameters.Add(new SqlParameter("@p_win",SqlDbType.Decimal,14,ParameterDirection.Output,false,0,0,string.Empty,  DataRowVersion.Default, null)); //保本价
    cm.Parameters.Add(new SqlParameter("@p_error",SqlDbType.VarChar,40,ParameterDirection.Output,false,0,0,string.Empty,  DataRowVersion.Default, null)); //错误信息
    cm.Parameters.Add(new SqlParameter("returnvalue",SqlDbType.Int,4,ParameterDirection.ReturnValue, false, 0, 0,string.Empty, DataRowVersion.Default, null));

    cm.Parameters["@p_userid"].Value=System.Convert.ToInt16(HttpContext.Current.Session["UserId"]);
    //cm.Parameters["@p_userid"].Value= 1;
    cm.Parameters["@p_stockcode"].Value = StockCode;
    cm.Parameters["@p_excode"].Value = ExCode;
    cm.Parameters["@p_bsflag"].Value = BsFlag;
    cm.Parameters["@p_newprice"].Value = NewPrice;
    cm.ExecuteNonQuery();
    ReturnValue = cm.Parameters["returnvalue"].Value.ToString();
    FreeCp = cm.Parameters["@p_freecp"].Value.ToString();
    CanBuy = cm.Parameters["@p_canbuy"].Value.ToString();
    CanSell = cm.Parameters["@p_cansell"].Value.ToString();
    Win = cm.Parameters["@p_win"].Value.ToString();
    ErrorInfo = cm.Parameters["@p_error"].Value.ToString(); //========================================================================
    } public string ErrorInfo;
    public string FreeCp;
    public string CanBuy;
    public string CanSell;
    public string Win; }
      

  3.   

    为什么我在编译的时候出现未定义 sqldatasetcommand???
      

  4.   

    给你一些我整理过得的代码:
    (1)、不带输入、输出参数的简单的存储过程调用。
    存储过程内容:
    CREATE PROCEDURE pro AS
    select * from 报表清单调用方法:
    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection myConnection = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=南糖;Data Source=DOT_NET_SERVER"); 
    myConnection.Open(); 
    SqlDataAdapter myCommand = new SqlDataAdapter("pro", myConnection); //pro是存储过程名
    //设置命令对象类型为存储过程
    myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
     
    DataSet ds = new DataSet(); 
    myCommand.Fill(ds, "报表清单"); 
    DataGrid1.DataSource=ds.Tables["报表清单"].DefaultView;
    DataGrid1.DataBind();
    }(2)、带输入参数的存储过程的调用
    存储过程内容:
    CREATE PROCEDURE pro_inputpara @bbid  varchar(10)  AS
    select 报表编号,报表名称 from 报表清单 where 报表编号=@bbid调用方法:
    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection myConnection = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=南糖;Data Source=DOT_NET_SERVER"); 
    myConnection.Open(); 
    SqlDataAdapter myCommand = new SqlDataAdapter("pro_inputpara", myConnection);
    myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;myCommand.SelectCommand.Parameters.Add(new SqlParameter("@bbid", SqlDbType.NVarChar, 15));
    myCommand.SelectCommand.Parameters["@bbid"].Value = "sb0001";//传递参数

    DataSet ds = new DataSet(); 
    myCommand.Fill(ds, "报表清单"); 
    DataTable dt = ds.Tables["报表清单"];
    this.DataGrid1.DataSource = dt.DefaultView;
    this.DataGrid1.DataBind();
    }
      

  5.   

    CREATE PROCEDURE selectIDFromName
      @Firstname varchar,
      @LastName varchar,
      @Id int OUTPUT
    As  SELECT @ID = UserID
       FORM tblUsers
      WHERE FirstName =@FirstName
      AND LastName = @LastName