小成博客

2010年到了...
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

不带参数存储过程的使用-(绑定datalist)

Posted on 2007-07-04 22:52  成斌  阅读(152)  评论(0)    收藏  举报
SqlConnection myConnection = new SqlConnection(SqlConn.Connection);
myConnection.Open();

SqlDataAdapter myCommand 
= new SqlDataAdapter();
myCommand.SelectCommand = new SqlCommand();
myCommand.SelectCommand.Connection 
= myConnection;
myCommand.SelectCommand.CommandText 
= "GradeList";
myCommand.SelectCommand.CommandType 
= CommandType.StoredProcedure;

DataSet ds 
= new DataSet();
myCommand.Fill(ds);


if (ds != null && ds.Tables[0].Rows.Count > 0)
{
    
this.GradeName.DataSource = ds;
    
this.GradeName.DataTextField = "GradeName";
    
this.GradeName.DataValueField = "GradeName";
    
this.GradeName.DataBind();
    
this.GradeName.Items.Insert(0new ListItem(GradeName, "0"));
    
this.GradeName.SelectedIndex = 0;
}


myConnection.Close();