asp.net中如何将文本框的内容写入access数据库
已经可以成功运行,但是在写入access数据库的时候报错了,一直搞不清是什么错误,希望高手们帮我解决难题,感谢
这段代码是在 About.aspx.cs中写的
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["12"] != null)
Label1.Text = Session["12"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
string a = TextBox1.Text.Trim();
DateTime begin = DateTime.Parse(a);
string b = TextBox2.Text.Trim();
DateTime over = DateTime.Parse(b);
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= D:\My Documents\Visual Studio 2010\WebSites\WebSite2\App_Data\db1.mdb";
OleDbCommand comm = new OleDbCommand();
conn.Open();
comm.Connection = conn;
comm.CommandText = "Insert Into Time (begin,over) Values ('" + a + "','" + b +"' )";
comm.ExecuteNonQuery();
conn.Close();
}
}
我有两个文本框,一个是开始的时间,一个是结束的时间,然后再access中是begin跟over ,运行后报错
comm.ExecuteNonQuery() 用户代码未处理,oledbexception,insert into 语句的语法错误