请问我在数据库中输入了一定量的数据!
有一个  A 表   中有  1  , 2  ,3  等数据!
我要如何才能够访问到其中A 表 的 2 数据!
显示在我的dataGridView1 控键中呢?
是用C#  编写的!跪求!!!!!!!!!!!

解决方案 »

  1.   


    第2行的第1列
    string ss = dataGridView1.Rows[1][0].ToString();
    第2行的第2列
    string ss = dataGridView1.Rows[1][1].ToString();
    第2行的第3列
    string ss = dataGridView1.Rows[1][2].ToString();
    .........................
      

  2.   

    private void button2_Click(object sender, EventArgs e)
    {              
      string strSql = "select * from 人员信息 ";
                    dt = link.relateData(strSql);
                    dataGridView1.DataSource = dt;
                    cmdOrders = (CurrencyManager)BindingContext[dt];
    }        internal DataTable relateData(string strSql)
            {
                using (SqlConnection conn = new SqlConnection(connectString))
                {
                    conn.Open();
                    SqlDataAdapter da = new SqlDataAdapter(strSql, conn);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "temptable");
                    DataTable dt = ds.Tables["temptable"];
                    return dt;
                }
            }我这样写就是把所有的数据都输出   如何才能查找输出呢??
    急!!!!!鬼求!!!
      

  3.   

    private void button2_Click(object sender, EventArgs e) 
    {              
      string strSql = "select * from 人员信息 where Id = 2"; 
                    dt = link.relateData(strSql); 
                    dataGridView1.DataSource = dt; 
                    cmdOrders = (CurrencyManager)BindingContext[dt]; 

      

  4.   


    using System.Data;
    using System.Data.SqlClient;//读库,绑定//col1 col2 col3
    //1    2     3
    //则可用 sql = "select col2 from A";//col1  col2  col3
    // 1     aa    aaaa
    // 2     bb    bbbb
    // 3     cc    cccc
    //则可用 sql = "select * from A where col1=2";//假设为第二种情况
    string connStr = "server=.;uid=sa;pwd=;database=myDB";  //myDB为数据库名
    SqlConnection conn = new SqlConnection(connStr);
    string sql = "select * from A where col1=2";
    SqlDataAdapter adp = new SqlDataAdapter(sql,conn);
    DataTable dt = new DataTable();
    adp.Fill(dt);
    this.DataGridView1.DataSource = dt.DefaultView;