SqlDataReader对象使用例子

SqlDataReader对象使用例子

if(!this.IsPostBack )

   {

    SqlConnection con=new SqlConnection( "server=.;database=MsgBoard;uid=sa;pwd=sa");

    con.Open();

    string mysql="select * from MsgBoard";

    SqlCommand cmd=new SqlCommand(mysql,con);

    cmd.Connection=con;  

    //Command对象的ExecuteReader方法,返回值为SqlDataReader

    SqlDataReader sdr  = cmd.ExecuteReader();

    while (sdr.Read())

    {

     // get the results of each column

     string Name = (string)sdr["MsgWriter"];

     string Content = (string)sdr["MsgContent"];

     string MyTime    = (string)sdr["MsgTime"];

     // print out the results

     this.lblWriter.Text=Name.ToString();

     this.tetContent.Text =Content.ToString();

     this.lblTime.Text=MyTime;

    }              
    con.Close();
   }

你可能感兴趣的:(mysql,server,String,cmd,each)