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"] ;
谢谢楼上的, 可是, 我要的是ODBC的,不是sql的我机器sql的我搞不定,只会用ODBC连
你用的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!了.以上是在这里手写的,可能有错误,不过大错没有哈.
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];
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"];
今天好像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"];
今天好像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"];
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"] ;
可是,
我要的是ODBC的,不是sql的我机器sql的我搞不定,只会用ODBC连
如果是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!了.以上是在这里手写的,可能有错误,不过大错没有哈.
楼主我错了.
ODBC我没有用过.
我们用AR
那可是最重要的dataGrid.DataBind();
注意啊.
楼主的问题,好多人关注哈,打开的时候还没有人回贴,
发完了贴以后却在三楼.晕!
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];
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"];
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"];
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"];
现在想用datagrid显示数据。你用你的fill方法实现了么?
jiatong1981 交个朋友吧,谢谢你的帮忙
http://topic.csdn.net/u/20071027/17/62146c3d-ae84-46d2-8acf-17aa6aedc5a2.html
sqlstr.open();
Sqldataadapater ad= new Sqldataadapater ();
Dataset ds=new Dataset();
Ad.Fill(ds,"title");
datagrid1.Datasource=ds;
datagrid1.DataBind();
sqlstr.close();