我做了个连接数据库的程序,但是不知道怎么写查询的代码,希望高手写个简单的代码让我做下参考,谢谢。 
              {
                sconn = new SqlConnection(@"Integrated Security=SSPI;server=(local);database=pubs");
                sconn.Open();
                }          private void button2_Click(object sender, EventArgs e)
          {
              string commstr = @"select * from titles";
              scomm = new SqlCommand(commstr, sconn);
              sdr = scomm.ExecuteReader();
              if (sdr.Read())
              {
                  textBox1.Text = sdr.GetValue(1).ToString();
                  textBox2.Text = sdr.GetValue(2).ToString();
              }
          }

解决方案 »

  1.   

    SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;server=local);database=pubs"); 
    string mysql="select * from titles"; 
    SqlDataAdapter myDapter=new SqlDataAdapter(mysql,conn);
    DataSet ds=new DataSet(); 
    myDapter.Fill(ds); 
    DataTable dt = ds.Tables[0]; 
    if(dt.Rows.Count >=1) 
    textBox1.Text  = dt.Rows[0][0].ToString();
    textBox2.Text  = dt.Rows[0][1].ToString();
      

  2.   


    SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;server=local);database=pubs");  
    string mysql="select * from titles";  
    SqlDataAdapter myDapter=new SqlDataAdapter(mysql,conn); 
    DataSet ds=new DataSet();  
    myDapter.Fill(ds);  
    DataTable dt = ds.Tables[0];  
    if(dt.Rows.Count  >=1)  
    {
    textBox1.Text  = dt.Rows[0][0].ToString(); 
    textBox2.Text  = dt.Rows[0][1].ToString(); 
    }
      

  3.   

    建议楼主看看有关ADO.net方面的书或知识!!!
    最基本的连接数据库!...
    仅靠在这里提问...学到的很少!很少!