用command对象,结果给datareader,在调用getstring(0)SqlConnection myconn=new SqlConnection("...");
myconn.Open();
SqlCommand mycommand=new SqlCommand(sql,myconn);
SqlDataReader myreader=mycommand.ExecuteReader();
while (myreader.Read())
{
  text1.text=myreader.GetString(0);
}
myreader.Close();
myconn.Close();

解决方案 »

  1.   

    我用的是oledbdatasetcommand,不是datareader这样不行吗?
      

  2.   

    同样存在OleDbDataReader, OleDbCommand
      

  3.   

    把select sum(score) from tables1 where field=1
    改写成select sum(score) as one,count(*) as two from tables1 where field=1然后在把ONE当作字段来访问.
      

  4.   

    string sql=select sum(score) from tables1 where field=1;
    OleDbCommand cmd=new OleDbCommand(sql,conn);
    TextBox1.Text=(string)cmd.ExecuteScalar();
      

  5.   

    to  luningjfy_2001(ln) 
    执行了sql后,我该怎么把它给text?
    m_contentSQL = "select sum(gjsl) as zh from " & Session("ywnameid1") & " where " & Session("bcxid") 
            m_objdscommand = New OleDbDataAdapter(m_contentSQL, "Provider=MSDAORA.1;Password=swpi;User ID=toollib;Data Source=connect_toollib")
            m_objdscommand.Fill(m_objdataset, "appd_tabs")         m_objtable = m_objdataset.Tables("appd_tabs") 
            myview = m_objtable.DefaultView        TextBox1.Text = ??(这个地方怎么写?)
            TextBox1.DataBind()
      

  6.   

    试试
    TextBox1.Text=((TextBox)m_objtable.DefaultView[0]).Text
      

  7.   

    TextBox1.Text = ??(这个地方怎么写?)
    TextBox1.DataBind()
    可将以上两句改为
    TextBox1.DataBind("Text",m_objdataset,appd_tabs.zh)
    因为DataBind有三个参数可选。