使用的工具是VS2010,Access2010
错误提示:在 ConnectionString 中未指定 OLE DB 提供程序。示例为:“Provider=SQLOLEDB;”
代码如下:
login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Web.Configuration;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string user_name, user_pw, real_name, title, school, department, phone_number, email;
user_name = UserText.Text.Replace("'", "''");
user_pw = PassText.Text.Replace("'", "''");
real_name = NameText.Text.Replace("'", "''");
title = TitleText.Text.Replace("'", "''");
school = SchoolText.Text.Replace("'", "''");
department = DepartmentText.Text.Replace("'", "''");
phone_number = PhoneText.Text.Replace("'", "''");
email = EmailText.Text.Replace("'", "''");
string strConn = WebConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string sql = "insert into userinfo (user_name,user_pw,real_name,title,school,department,phone_number,email)values]('" + user_name + "','" + user_pw + "','" + real_name + "','" + title + "','" + school + "','" + department + "','" + phone_number + "','" + email + "')";
OleDbCommand cmd = new OleDbCommand(sql,conn);
cmd.ExecuteNonQuery();
conn.Close();
}
private void CheckInput()
{
throw new NotImplementedException();
}
protected void UserText_TextChanged(object sender, EventArgs e)
{
}
}
web.config
connectionString="Provider=Microsoft.Jet.OleDb.4.0;Data ;
Data source=D:\My Documents\Documents\Database3.accdb;
Persist Security Info=False;"/>
查了很多解决办法均失败,求大神指教