新人啊,这几天看了这一块,也在网上查了相关资料,总是没有确切的答案,请高手给解啊,
假设在一个ASP.NET WEB应用程序中,有一个ID=Button1 的Button ,和VISIO2003相连的数据库为本地SQL2000提供的数据库名为anttest 和Button相连的数据库连接名为conn,现要实现点击Button则执行SQL数据语句select 执行,并把结果显示在WEB页面中,具体杂处理

解决方案 »

  1.   

    晕死
    你就不会用邦定什么的?
    你去看看ADO
    直接打开MSDN,慢慢翻看
    里面有很多例子
      

  2.   

    private void Button1_Click(object sender, System.EventArgs e)
    {
        string str = "server=.;uid=sa;pwd=;database=anttest";
        SqlConnection conn = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand("select * from yourtable", conn);    conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();    while (dr.Read())
        {
            Response.Write(dr.GetValue(0).ToString() + dr.GetValue(1).ToString() + "<br />");
        }    dr.Close();
        conn.Close();
    }
      

  3.   

    我想读出这个表的所有列这么写亚.我用System.Console.WriteLine(dr.GetValues() "<br />");报错.
      

  4.   

    把查询到的结果用一个LIST返回.
      

  5.   

    Console.WriteLine 是控制台应用程序中使用的。
    代码可以参考“amandag(高歌)” 的
      

  6.   

    你也可以把查询到的数据绑定到一个datagrid中,这样不就可以看到你所查询的结果了吗
      

  7.   

    //请自己改数据库名,表名
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        string str = @"server=.\sqlExpress;uid=sa;pwd=sa;database=pubs";
        SqlConnection conn = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand("select * from authors", conn);    conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();    while (dr.Read())
        {
            for (int i = 0; i < dr.FieldCount - 1; i++ )
                Response.Write(dr.GetValue(i).ToString() + " ");
            Response.Write("<br>");
        }    dr.Close();
        conn.Close();
    }
      

  8.   

    - -!
    先看看书吧
    CSDN不是万能的,到这里把书都扔了
      

  9.   

    private void Button1_Click(object sender, System.EventArgs e)
            {
                string str = "server=.;uid=sa;pwd=;database=anttest";
                SqlConnection conn = new SqlConnection(str);
                conn.Open();
                DataSet ds = new DataSet();
                SqlDataAdapter ap = new SqlDataAdapter("select * from yourtable", conn);
                ap.Fill(ds);
                conn.Close();
                DataGrid1.DataSource=ds;
                DataGrid1.DataBind();        }
      

  10.   

    谢谢大家,已经解决了哈,特别感谢angelzjk,amandag(高歌
      

  11.   

    private  void  Button1_Click(object  sender,  System.EventArgs  e)  
                   {  
                           string  str  =    "server=.;uid=sa;pwd=;database=anttest  ";  
                           SqlConnection  conn  =  new  SqlConnection(str);  
                           conn.Open();  
                           DataSet  ds  =  new  DataSet();  
                           SqlDataAdapter  ap  =  new  SqlDataAdapter(  "select  *  from  yourtable  ",  conn);  
                           ap.Fill(ds);  
                           conn.Close();  
                           DataGrid1.DataSource=ds;  
                           DataGrid1.DataBind();  
     
                   } 
    这种方式在编译过程中提示缺少using
      

  12.   

    DataGrid1.DataBind();  这个没有啊.
      

  13.   

    using System.Data;
    using System.Data.SqlClient;