找了半天了,实在没有找到什么办法,谁能给我提供一段代码;
将sql sever 中cheng库中的employee表显示在dataGrid控件里。
太谢谢了!!!!!!!!!!

解决方案 »

  1.   


    DataSet ds = new DataSet();
    string strConn = "SERVER=127.0.0.1;DATABASE=cheng;UID=SA;PWD=";   //数据库连接字符串 
    SqlConnection conn = new SqlConnection(strConn); 
    string strSql = "SELECT * FROM employee"; 
    SqlDataAdapter sda = new SqlDataAdapter(strSql, conn); 
    sda.Fill(ds, "employee"); 
    this.dataGrid1.DataSource = ds.Tables["employee"] ; 
      

  2.   

    谢谢楼上的,
    可是,
    我要的是ODBC的,不是sql的我机器sql的我搞不定,只会用ODBC连
      

  3.   

    你用的VS2003还是VS2005啊.
    如果是VS2005就太好办了.
    2003就有一些麻烦.
    我用的2005,2003好久不用了找不到代码,只能这样写了.可能大小写不对哈.
    using System.data;
    using System.data.SqlClient;
    定义SqlConnection con = new SqlConnection("连接字符串,如:database='cheng' Uid='sa' Pwd=''等");
    SqlDataAdapter da = new SqlDataAdapter("这里是查询语句:Select * from Employee",con); //con是上面的联接对象.
    DataSet ds = new DataSet();
    da.Fill(ds);//如果是一张表就可以这样了.
    return ds;//如果你把它提出来,可以返回个DataSet或不返回,在这里绑定.
    this.DataGrid1.DataSource = ds;//呵呵,写到这了才知道你用的是2003,在2005里是GridView;呵呵.
    DataGrid1.DataBind();好了OK!了.以上是在这里手写的,可能有错误,不过大错没有哈.
      

  4.   

    不会吧,发完贴后怎么是在三楼啊.
    楼主我错了.
    ODBC我没有用过.
    我们用AR
      

  5.   

    补一句,一楼的Code少了一行代码,
    那可是最重要的dataGrid.DataBind();
    注意啊.
    楼主的问题,好多人关注哈,打开的时候还没有人回贴,
    发完了贴以后却在三楼.晕!
      

  6.   


    using System.Data.Odbc;
    ……
    DataSet ds = new DataSet();
    OdbcConnection oconn = new OdbcConnection("DSN=Cheng;UID=sa;PWD=");
    OdbcDataAdapter oda = new OdbcDataAdapter("select * from customers", oconn);
    oda.Fill(ds, "customers");
    this.dataGridView1.DataSource = ds.Tables[1];
      

  7.   


    using System.Data.Odbc;
    ……
    DataSet ds = new DataSet();
    OdbcConnection oconn = new OdbcConnection("DSN=Cheng;UID=sa;PWD=");
    OdbcDataAdapter oda = new OdbcDataAdapter("select * from customers", oconn);
    oda.Fill(ds, "employee");
    this.dataGrid1.DataSource = ds.Tables["employee"];
      

  8.   

    今天好像csdn不稳定啊 动不动就出错哦 
    using System.Data.Odbc;
    ……
    DataSet ds = new DataSet();
    OdbcConnection oconn = new OdbcConnection("DSN=Cheng;UID=sa;PWD=");
    OdbcDataAdapter oda = new OdbcDataAdapter("select * from employee", oconn);
    oda.Fill(ds, "employee");
    this.dataGrid1.DataSource = ds.Tables["employee"];
      

  9.   

    今天好像csdn不稳定啊 动不动就出错哦 
    using System.Data.Odbc;
    ……
    DataSet ds = new DataSet();
    OdbcConnection oconn = new OdbcConnection("DSN=Cheng;UID=sa;PWD=");
    OdbcDataAdapter oda = new OdbcDataAdapter("select * from employee", oconn);
    oda.Fill(ds, "employee");
    this.dataGrid1.DataSource = ds.Tables["employee"];
      

  10.   

    需要首先在 控制面板->管理工具->数据源(ODBC)中首先配置好一个DSN(SQL Server)
      

  11.   

    提示什么错误 odbc有无配置好?
      

  12.   

    odbc是设计好的,之前可以完成向数据库写数据了
    现在想用datagrid显示数据。你用你的fill方法实现了么?
      

  13.   

    感谢同志们,问题解决了,jiatong1981 的代码真确,是我自己把sql语句写错了
    jiatong1981 交个朋友吧,谢谢你的帮忙
      

  14.   

    你可以看下我的贴子,datareader分页,access,sql2000,sql2005通吃,如果你看懂代码,外观的控制就太简单了,只需要要response.write中加 <table <tr > <td >就行了,还用啥datagrid控件,呵呵,本人比较懒,不愿意用那些控件,外观限制多,不好控制~ 
    http://topic.csdn.net/u/20071027/17/62146c3d-ae84-46d2-8acf-17aa6aedc5a2.html
      

  15.   

    Sqlconnection sqlstr= new Sqlconnection("server=(local);UID=sa;PWD=;DataBase=");
    sqlstr.open();
    Sqldataadapater ad= new  Sqldataadapater ();
    Dataset ds=new Dataset();
    Ad.Fill(ds,"title");
    datagrid1.Datasource=ds;
    datagrid1.DataBind();
    sqlstr.close();