代码无误,却插不进数据库
用.net和access作的,编译通过可是,当输入用户名,密码等等时,却总是出现“添加失败”,
困扰我好几天了,并且我的access数据库也已经加入了everyone 的“写的权限”了,哪位高手能
帮帮忙,真是要抓狂了。。。。
代码如下: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 Region : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnClear_Click(object sender, EventArgs e)
{
tbxLoginName.Text = " ";
tbxBlogName.Text = " ";
tbxPassword.Text = " ";
tbxEmail.Text = " ";
}
protected void btnRegion_Click(object sender, EventArgs e)
{
//string strConnection = "Provider=Microsoft.Jet.OleDb.4.0; ";
//strConnection += @ "Data Source=E:\BLOGDB.mdb ";
OleDbConnection objConnection = new OleDbConnection( "provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Server.MapPath( "BLOG.mdb "));
// OleDbConnection objConnection = new OleDbConnection(strConnection);
try
{if(objConnection .State ==ConnectionState.Closed )
objConnection .Open();
string inn = "insert into USER_INFO (LoginName,Password,BlogName,Email) values( ' "+this.tbxLoginName.Text.Trim()+ " ', ' "+this.tbxPassword.Text.Trim()+ " ', ' "+this.tbxBlogName.Text.Trim()+ " ', ' "+this.tbxEmail.Text.Trim()+ " ') ";
OleDbCommand cmd = new OleDbCommand(inn, objConnection);
// objConnection.Open();
cmd.ExecuteNonQuery();
objConnection.Close();
Response.Write( " <script language=javascript> ");
Response.Write( "alert( '添加成功! '); ");
//Response.Write( "history.go(-1); ");
Response.Write( " </script> ");
objConnection.Close();
}
catch
{
Response.Write( " <script language=javascript> ");
Response.Write( "alert( '添加失败! '); ");
//Response.Write( "history.go(-1); ");
Response.Write( " </script> ");
}
}
}