在web.config中配置链接字符串
程序页面中的数据写入操作
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; OleDbConnection conn = new OleDbConnection(connStr); string sql = "insert into [WriteName] (myName) values ('" + IUserName.Text + "')"; OleDbCommand rs = new OleDbCommand(sql, conn); rs.Connection.Open(); rs.ExecuteNonQuery(); rs.Connection.Close();
GradView显示数据
使用DataGrid显示数据库
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/my.mdb"); OleDbConnection conn = new OleDbConnection(connString); string sql = "select [ID] as 号, [MyName] as 姓名 from [WriteName]"; OleDbDataAdapter comm = new OleDbDataAdapter(sql, conn); DataSet rs = new DataSet(); comm.Fill(rs,"WriteName"); myDataList.DataSource = rs.Tables["WriteName"].DefaultView; myDataList.DataBind();
控件DataGride显示数据