C#连接SQL SERVER 数据库

private void Data_Bind()
  {
   try
   {
    SqlConnection conn=new SqlConnection("server=服务器名;uid=server用户名;pwd=server密码;database=数据库;");
    SqlDataAdapter myAdp=new  SqlDataAdapter("SELECT a, b FROM table",conn);
    DataSet dst=new DataSet();
    myAdp.Fill(dst);
    comboBox1.DataSource=dst.Tables[0].DefaultView;
    comboBox1.DisplayMember="a";
    comboBox1.ValueMember="b";
    
   }
   catch(System.Exception err)
   {
    MessageBox.Show(err.Message,this.Text);
   }
  }
posted on 2005-12-24 22:18  欲狼  阅读(1685)  评论(0)    收藏  举报