日期:2014-05-19  浏览次数:20915 次

寻求C# 的ado.net访问数据库的实例
谢谢
我刚学,还不会

------解决方案--------------------
SqlConnection conn = new SqlConnection( "server=192.168.1.26;uid=sa;pwd=;database=pubs; ");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter( "select au_id, au_lname, au_fname from authors order by au_id ", conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.ListBox1.DataSource = ds.Tables[0].DefaultView;
this.ListBox1.DataTextField= "au_lname ";
this.ListBox1.DataValueField= "au_id ";
this.ListBox1.DataBind();
------解决方案--------------------
别忘了这个
using System.Data.SqlClient;
------解决方案--------------------
你在csdn的搜索 中搜索ado.net 已经有很多类似的帖子了。
------解决方案--------------------
Web.config文件中
<add key= "CONNECTIONSTRING " value= "user id=SYS;data source=XXGL;password=SYS "> </add>

aspx.cs文件中
using System.Data.OracleClient;

OracleConnection MyConnection=new OracleConnection();
DataSet ds=new DataSet();
MyConnection.ConnectionString=System.Configuration.ConfigurationSettings.AppSettings[ "SQLCONNECTIONSTRING "].ToString();
MyConnection.Open();
OracleDataAdapter dr=new OracleDataAdapter( "select * from XXJCB ",MyConnection);
dr.Fill(ds);
MyConnection.Close();

以上代码针对oracle
------解决方案--------------------
对,多搜点电子书看,或者去买本入门书,最好带光盘的,哈哈
------解决方案--------------------
sqlhelper

------解决方案--------------------
关注
------解决方案--------------------
using System.Data.SqlClient;
连接字符串最好写在Config文件中;
<configuration>
<appSettings>
<add key= "SQLCONNECTIONSTRING " value= "data source=.;uid=sa;pwd=sa;database=NorthWind "> </add>
</appSettings>
</configuration>

取连接串的时候记得
using System.Configuration;

------解决方案--------------------

SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings[ "SQLCONNECTIONSTRING "].ToString());