请问怎样写C#读取sql2000的一个数值,如
在TextBox1中显示sql2000数据库中的一个数值,谢谢!

解决方案 »

  1.   

    SqlConnection conn = new SqlConnection("连接字串");
    SqlCommand cmd = new SqlCommand("你的SQL语句",conn);
    try
    {
    int total = (int)cmd.ExecuteScalar();
    conn.Close();
    }
    catch
    {
    HttpContext.Current.Response.Redirect("error.aspx?type=other");
    }
    finally
    {}
      

  2.   

    SqlConnection conn = new SqlConnection("连接字串");
    SqlCommand cmd = new SqlCommand("你的SQL语句",conn);
    try
    {
    int total = (int)cmd.ExecuteScalar();
    conn.Close();
    }
    catch
    {
    HttpContext.Current.Response.Redirect("error.aspx?type=other");
    }
    finally
    {}
      

  3.   

    SQL ="select * from table where name='test'";
    SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectString"]);
    myConnection.Open();SqlCommand myCommand = new SqlCommand(SQL,myConnection);
    SqlDataReader myReader= myCommand.ExecuteReader();
    while(myReader.Read())
    {
      TextBox1.Text=myReader["name"].ToString();
       .....}
    myReader.Close();
      

  4.   

    sql = "select mycol from mytable where 1=1";
    在写一个sqlcommand,执行sql语句,可以返回dataset或者datareader或者直接excutescalar
    具体代码自己找找,这个上面或者msdn上多多的
      

  5.   

    回复人: baobei7758(陵少) ( ) 信誉:100