我用sql2005建了一个名为abc的数据库,数据库包含一个表,表分为ID,Name,Address,请问我怎样链接并通过ID查询表中的信息啊?我用的vs2008,我是新手,麻烦大家帮忙,尽量详细哦,谢谢!

解决方案 »

  1.   

    select * from table where id=''
      

  2.   

    建议lz还是先找本SQL的书看看,如果最基本的都不会,这样问也不是办法,最好可以看看基础的东西
      

  3.   

    先在你的窗体里拉一个dataGridView1 直接复制一下我的代码就行了 
    string connecttionString="Data Source=.;Initial Catalog=abc;Persist Security Info=True;User ID=sa;Password=123456"; 
    SqlCommand cmd = new SqlCommand(); 
                  cmd.CommandText = "select * from  abc  where ID="+在这里写要查询的ID;             DataSet ds = new DataSet(); 
                using (SqlConnection conn = new SqlConnection(connecttionString)) 
                { 
                  cmd.Connection = conn;                 SqlDataAdapter adapter = new SqlDataAdapter(); 
                    adapter.SelectCommand = cmd;                 adapter.Fill(ds); 
                } 
                DataTable table = ds.Tables; 
      dataGridView1.DataSource=table ; 如果是Bs就是Web里加上这个dataGridView1.DataBind(); 
    否则不用的