急,高分给!想利用按钮事件调用存储过程,来把数据表里的数据全都取出来!!

解决方案 »

  1.   

    CREATE PROCEDURE tempproc
    AS 
    SELECT * FROM 表
    GO
    SqlCommand SqlComm=new SqlCommand();
    SqlComm.CommandText="tempproc";
    SqlComm.CommandType="StoredProcedure";
      

  2.   

    还要加上SqlCommand.connection=con(你的连接)才行
      

  3.   

    public SqlDataReader GetCountry()
    {
    SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    SqlCommand myCommand = new SqlCommand("SPr_GetCountry",myConn);
    myCommand.CommandType = CommandType.StoredProcedure; myConn.Open();
    SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
    return myReader;
    }
      

  4.   

    private void button1_Click(object sender, System.EventArgs e)
    {
    string sCata="Provider=\"SQLOLEDB.1\";workstation id=\"WJJ-ETGATE\";packet size=4096;user id=sa;integrated security=SSPI;data source=\"WJJ-ETGATE\";persist security info=False;initial catalog=数据库名";
    OleDbConnection sCnt=new OleDbConnection(sCata);
    sCnt.Open();
    string sqlStr="GetVegetables";
    OleDbCommand OleCmd=new OleDbCommand(sqlStr,sCnt);
    OleCmd.CommandType=CommandType.StoredProcedure;
    OleDbParameter sqlPter=OleCmd.Parameters.Add("@Kind",OleDbType.Char,20);
    sqlPter.Direction=ParameterDirection.Input;
    sqlPter.Value=参数值;
    OleDbDataAdapter sqlDap=new OleDbDataAdapter();
    sqlDap.SelectCommand=OleCmd;
    DataSet DS=new DataSet();
    sqlDap.Fill(DS);
    dataGrid1.DataSource=DS.Tables[0];
    sCnt.Close();
    }
      

  5.   

    上面中的string sqlStr="GetVegetables";//GetVegetables是存储过程名