asp.net怎样和数据库连接起来??

来源:百度知道 编辑:UC知道 时间:2024/05/04 04:58:06
呵呵,各位高手,最好能举个例子加以说明.

using System.Data;
using System.Data.OleDb;
private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection conn=new OleDbConnection("provider=sqloledb.1;data source=.;initial catalog=pubs;user id=sa;pwd=");
conn.Open();
OleDbCommand cmd=new OleDbCommand("select * from titles",conn);
OleDbDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
Response.Write(dr.GetString(0)+"<br>");
}
dr.Close();
conn.Close(); }