2.0中 Access数据库 连接

<p>方案&lt;一&gt;</p>
<p>配置文件中:</p>
<p>&lt;connectionStrings&gt;</p>
<p> &lt;add name="StrData" connectionString="App_Data/movie.mdb"/&gt;<br> &lt;/connectionStrings&gt;<br></p>
<p>代码调用:</p>
<p>string ACConnectionString = "Provider = Microsoft.Jet.OleDb.4.0; Data Source = " + HttpContext.Current.Server.MapPath(ConfigurationManager.ConnectionStrings["StrData"].ConnectionString);<br> OleDbConnection conn = new OleDbConnection(ACConnectionString);<br> conn.Open();<br> string sql = "select * from USERS where uname='" + TxtName.Text + "' and pass='" + TxtPwd.Text + "' ";<br> OleDbCommand cmd = new OleDbCommand(sql, conn);<br> OleDbDataReader dr = cmd.ExecuteReader();<br> if (dr.Read())<br> {<br> Response.Redirect("reg.aspx");<br> }<br> else<br> {<br> Response.Write("Roung");<br> }<br> conn.Close();</p>
<p>方案&lt;二&gt;</p>
<p>配置文件中:</p>
<p>&lt;connectionStrings&gt;<br> &lt;add name="StrData" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source =C:/Documents and Settings/SupperSdr/My Documents/Visual Studio 2005/WebSites/流媒体/App_Data/movie.mdb" providerName="System.Data.OleDb"/&gt;<br><br> &lt;/connectionStrings&gt;</p>
<p>代码调用:</p>
<p>OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["StrData"].ConnectionString );<br> conn.Open();<br> string sql = "select * from USERS where uname='" + TxtName.Text + "' and pass='"+ TxtPwd.Text +"' ";<br> OleDbCommand cmd = new OleDbCommand(sql, conn);<br> OleDbDataReader dr = cmd.ExecuteReader ();<br> if (dr.Read())<br> {<br> Response.Redirect("reg.aspx");<br> }<br> else<br> {<br> Response.Write("Roung");<br> }<br> conn.Close();</p>
<p></p>

你可能感兴趣的:(Access)