验证中...
Languages: ASP
Categories: 数据库相关
Latest update 2018-12-25 08:56
使用OleDbCommand类插入数据
Raw Copy
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class OleDbCmdTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//连接字符串
String sqlconn = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\工作\\asp.net\\ASP.NET 4.0基础教程\\源代码\\chap08\\chap08\\App_Data\\Northwind.mdb;Jet OLEDB:Database Password=111111";
OleDbConnection myConnection = new OleDbConnection(sqlconn);
//打开数据库连接
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand("select * from 运货商", myConnection);
OleDbDataReader myReader;
myReader = myCommand.ExecuteReader();
//获取数据之前,必须不断的调用Read方法,它负责前进到下一条记录.
Response.Write("<h3>使用OleDbCommand类读取数据</h3><hr>");
Response.Write("<table border=1 cellspacing=0 cellpadding=2>");
//显示列名字
Response.Write("<tr bgcolor=#DAB4B4>");
for (int i = 0; i < myReader.FieldCount; i++)
{
Response.Write("<td>" + myReader.GetName(i) + "</td>");
}
Response.Write("</tr>");
//输出所有的字段值
while (myReader.Read())
{
Response.Write("<tr>");
//打印取到的数据
for (int i = 0; i < myReader.FieldCount; i++)
{
Response.Write("<td>" + myReader[i].ToString() + "</td>");
}
Response.Write("</tr>");
}
Response.Write("</table>");
//关闭SqlDataReader
myReader.Close();
//关闭与数据库的连接
myConnection.Close();
}
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_sixth 5th_float_left_close