public DataTable GetAllByID(int EmployeeID)
        {
            DataTable dt = new DataTable();
            SqlConnection mathConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnections"].ToString());
            SqlCommand scmd = new SqlCommand();            this.scmd = new SqlCommand("GetAllByID", mathConnection);
            this.scmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter sAda = new SqlDataAdapter("GetAllByID", mathConnection);
            sAda.SelectCommand = scmd;
            sAda.SelectCommand.CommandType = CommandType.StoredProcedure;
            this.scmd.Parameters.Add("@myid", SqlDbType.Int);
            this.scmd.Parameters["@myid"].Value = EmployeeID;            try
            {
                this.mathConnection.Open();
                this.scmd.ExecuteNonQuery();
                this.sAda.Fill(ds);
                this.mathConnection.Close();
            }
            catch
            {
                throw null;
            }
            return dt;
        }
帮我看看有什么问题?谢谢!
编译不出错,运行绑不出数据!存储过程没有问题!求教

解决方案 »

  1.   

    SqlCommand scmd = new SqlCommand();this.scmd 是类的变量吧,不是上边声明的局部变量所以下边你给this.scmd赋得东西对sada没有任何用途
      

  2.   

    using (SqlConnection connection = 
            new SqlConnection(connectionString))
        {
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand scmd = new SqlCommand("GetAllByID", mathConnection);
            scmd.CommandType = CommandType.StoredProcedure;
            scmd.Parameters.Add("@myid", SqlDbType.Int);
            scmd.Parameters["@myid"].Value = EmployeeID;
            adapter.SelectCommand = scmd;
            adapter.Fill(dataset);
            return dataset.Tables[0];
        }