这是一个简单的数据插入脚本,我发现它正在写入access.db这是我从下面的代码中遇到的问题:
错误:第16行:Connection.Open()
如果您愿意让我知道究竟应该在代码中编辑什么,那就太棒了。
非常感谢
<%@ Page Language="VB" Debug="true"%>
<%@ Import Namespace="System.Data.Oledb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Page.IsPostBack = False Then
Label1.Visible = False
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Connection As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=C:\inetpub\wwwroot\Thinkdebt\customers.mdb")
Connection.Open()
Dim Command As New OleDbCommand("INSERT INTO tblCustomers(FirstName," & _
"LastName)VALUES(@FirstName,@LastName)", Connection)
Command.Parameters.Add(New OleDbParameter("@FirstName", TextBox1.Text))
Command.Parameters.Add(New OleDbParameter("@LastName", TextBox2.Text))
Command.ExecuteNonQuery()
Connection.Close()
Label1.Text = "Record inserted."
Label1.Visible = True
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id=Head1 runat="server">
<title>ASP.NET Form to Database Sample</title>
</head>
<body>
<div>
<h1>ASP.NET Form to Database</h1>
<form id="form1" runat="server">
First name:<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="Please enter a first name"></asp:RequiredFieldValidator><br /><br />
Last name:<asp:TextBox ID="TextBox2" runat="server" Text=""></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="TextBox2" runat="server" ErrorMessage="Please enter a last name"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID=Button1 runat="server" Text="Insert Record" OnClick="Button1_Click" />
<br />
<asp:Label ID=Label1 runat="server" Text=""></asp:Label>
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
jet.Oledb.4.0不适用于64Bit机器。
您可以将Microsoft.ACE.OLEDB.12.0用于64位系统。您可以检查它是32位还是64位系统。如果32位则使用.JET.OLEDB,否则使用ACE.OLEDB。
答案 1 :(得分:-1)
您正在使用Jet.OLEDB.4.0驱动程序,该驱动程序在64位系统上运行时出现该错误,最好安装新驱动程序Microsoft Access数据库引擎2010可再发行组件
http://www.microsoft.com/download/en/details.aspx?id=13255
你还需要从“Provider = Microsoft.Jet.OLEDB.4.0;更改连接字符串; “to”Provider = Microsoft.ACE.OLEDB.12.0;“
我的博客参考:64位版本的'Microsoft.Jet.OLEDB.4.0'Office 2007/2010 Jet驱动程序
希望这会有所帮助。