private void Form1_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection( "user id=hxh;password=20080712;initial catalog=hxh;Server=XINAN0107\SQLEXPRESS");
            conn.Open();
            DataTable dt = new DataTable();
            da.Fill(dt);
                
                    this.textBox1.Text = dt.Rows[0]["math"].ToString();
                    this.textBox2.Text = dt.Rows[0]["age"].ToString();
                    this.textBox3.Text = dt.Rows[0]["course"].ToString();
            conn.Close();
         }
远程连接已打开,Server填IP也不行,能不能给个代码,大谢!

解决方案 »

  1.   

    连接字符串中的Server改成Data Source试试看。
    顺便检查你的da(DataAdapter)是否初始化了。
      

  2.   

    lz……你的da在哪里初始化的?
    用DataSet实现更简单,有关Ds和Dt的关系和用法,参看这里:http://qing.94nn.com/article.asp?id=118
      

  3.   

    SqlConnection conn = new SqlConnection( "user id=hxh;password=20080712;initial catalog=hxh;Server=XINAN0107\SQLEXPRESS"); 
    conn.Open(); 
    SqlCommand cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT * FROM tablename";
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable(); 
    da.Fill(dt);                   
    this.textBox1.Text = dt.Rows[0]["math"].ToString(); 
    this.textBox2.Text = dt.Rows[0]["age"].ToString(); 
    this.textBox3.Text = dt.Rows[0]["course"].ToString(); 
    conn.Close();         
      

  4.   

    http://www.connectionstrings.com/?carrier=sqlserver2005
      

  5.   

    SqlConnection conn = new SqlConnection( "user id=hxh;password=20080712;initial catalog=hxh;Server=XINAN0107\\SQLEXPRESS"); 
      

  6.   

     private void Form1_Load(object sender, EventArgs e)
            {
               SqlConnection conn = new SqlConnection( "user id=hxh;password=20080712;initial catalog=hxh;Server=XINAN0107\SQLEXPRESS"); 
               conn.Open(); 
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT * FROM Student";
               SqlDataAdapter da = new SqlDataAdapter(cmd);
                 DataTable dt = new DataTable(); 
                da.Fill(dt);                   
                  this.textBox1.Text = dt.Rows[0]["math"].ToString(); 
                 this.textBox2.Text = dt.Rows[0]["age"].ToString(); 
                  this.textBox3.Text = dt.Rows[0]["course"].ToString(); 
                   conn.Close();         
            }
    还是连不上
      

  7.   

    连接字符串中缺少书库名,像这样server=.;uid=sa;pwd=1q2w3e;database=t
      

  8.   

    conn.Open(); 这句话能运行过去吗?