我用sql server中建立了一个数据库 并且建一个表,现在想用窗体中的按钮执行之后,几个textbook里面显示的是表某一行的几个字段,请问怎么办到,主要代码是什么样子的啊 

解决方案 »

  1.   


    //获取数据库数据并填充一个DataTable
    SqlConnection conn = new SqlConnection("连接数据库字符串");
    SqlDataAdapter da = new SqlDataAdapter("SQL查询语句",conn);
    conn.Open();
    DataTable dt = new DataTable();
    da.Fill(dt);
    da.Dispose();
    conn.Close();
    conn.Dispose();
    //把DataTable中的相关数据显示到界面中
    this.textBox1.Text = dt.Rows["行"]["列"].ToString();
    this.textBox2.Text = dt.Rows["行"]["列"].ToString();
    this.textBox3.Text = dt.Rows["行"]["列"].ToString();
    ..........................
      

  2.   

       我刚学 很多不会 
                SqlConnection conn = new SqlConnection("连接数据库字符串");
                SqlDataAdapter da = new SqlDataAdapter("SQL查询语句",conn);
     括号里面的具体写什么啊
      

  3.   

                        string Afile = "provider=microsoft.jet.OLEDB.4.0;Data source=" + name.into.nto("ServerPath") + "";
                        OleDbConnection AconnStr = new OleDbConnection(Afile);
                        OleDbCommand scmd = new OleDbCommand("select top 200 * from client where 字段='" + gainame + "' and 字段='" + comboBox3.Text.Trim() + "' order by id", AconnStr);
                        OleDbDataReader odr = null;
                        AconnStr.Open();
                        odr = scmd.ExecuteReader();
                        if (odr != null)
                        {
                            while (odr.Read())
                            {
                                textBox7.Text = odr["字段"].ToString();
                                textBox10.Text = odr["字段"].ToString();
                                textBox16.Text = odr["字段"].ToString();
                                textBox11.Text = odr["字段"].ToString();
                                textBox12.Text = odr["字段"].ToString();
                                textBox13.Text = odr["字段"].ToString();
                                textBox14.Text = odr["字段"].ToString();
                                textBox15.Text = odr["字段"].ToString();
                                comboBox3.Text = odr["字段"].ToString();
                            }
                            odr.Close();
      

  4.   

    你用的不是sql server 数据库吧
      

  5.   


    我觉得用SqlDataAdapter 填充数据最好不要手动打开连接和关闭连接,这些应该由SqlDataAdapter 自动完成
      

  6.   

    最后显示的却是这个东西。
    在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)
       我改了好多设置都不行  防火墙也关了了
    默认的设置在哪里可以看到啊
      

  7.   

    恩  搞了一天了 都没弄出来啊
        SqlConnection conn = new SqlConnection("Data Source=9AA7107A8CBE4FA;Initial Catalog=chengjibiao;;Persist Security Info=True;User ID =jfq;PassWord =123456;");
                conn.Open();
                SqlDataAdapter da = new SqlDataAdapter("select 姓名,数学,英语,语文 from 成绩表", conn);            DataTable dt = new DataTable();
                da.Fill(dt);
                
                this.textBox1.Text = dt.Rows[i]["数学"].ToString();
                this.textBox2.Text = dt.Rows[i]["语文"].ToString();
                this.textBox3.Text = dt.Rows[i]["姓名"].ToString();
                this.textBox4.Text = dt.Rows[i]["英语"].ToString();
                da.Dispose();
                conn.Close();
                conn.Dispose();
                
    老是说连接不了数据库  我把sql server 都改了n遍了  还是不行