一个简单的往数据库添加的问题
我要Windows身份认证,把已经验证的用户名添加到数据库中
可是在运行时总报错:INSERT INTO 语句的语法错误 我不知道怎么错的
帮忙看下
谢谢
protected void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs e)
{
OleDbConnection cnn = new OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\\example\\database.mdb ");
if(cnn.State == ConnectionState.Closed)
{
cnn.Open();
}
string str= "Insert Into regist (user_name,time) Values ( ' "+e.Identity .Name .ToString ()+ " ',GetDate()) ";
OleDbCommand cmd= new OleDbCommand (str);
cmd.Connection = cnn;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
------解决方案--------------------1。
string str= "Insert Into regist (user_name,time) Values ( ' "+e.Identity .Name .ToString ()+ " ',GetDate()) ";
》》》
string str= "Insert Into regist (user_name,[time]) Values ( ' "+e.Identity.Name
.ToString()+ " ',Date()) ";
string str= "Insert Into regist (user_name,[time]) Values ( ' "+e.Identity .Name .ToString ()+ " ',Now()) ";