| 发表于:2007-01-19 12:30:3316楼 得分:5 |
private void databind() { sqlconnection con = new sqlconnection( "server=(local);database=hr;uid=sa;pwd=; "); try { sqldataadapter cmd = new sqldataadapter( "select * from hr_user ", con); dataset ds = new dataset(); cmd.fill(ds, "hr_user "); this.datagridview1.datasource = ds.tables[ "hr_user "]; } catch (exception ex) { messagebox.show(ex.message.tostring()); } } sqldataadapter不需要打开connection的连接的,可以自动打开和关闭,但是这应该不是主要问题 应该没事的阿,连接字符串和表名与你的都一致的阿 | | |
|