初学,简单的插入一条记录进数据库,为什么就是不成功,帮忙看看。(无错误提示)
......
OleDbConnection conn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("../access/jssl.mdb"));
try
{
conn.Open();
OleDbCommand comm=new OleDbCommand();
comm.Connection=conn;
comm.CommandText="INSERT news (title,content) VALUES ('abc','abc')";
comm.ExecuteNonQuery();
}
catch(Exception error)
{
this.Response.Write(error.ToString());
}
finally
{
Response.Write("数据库连接成功!");
conn.Close();
}
......
......
OleDbConnection conn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("../access/jssl.mdb"));
try
{
conn.Open();
OleDbCommand comm=new OleDbCommand();
comm.Connection=conn;
comm.CommandText="INSERT news (title,content) VALUES ('abc','abc')";
comm.ExecuteNonQuery();
}
catch(Exception error)
{
this.Response.Write(error.ToString());
}
finally
{
Response.Write("数据库连接成功!");
conn.Close();
}
......
1、检查你的连接组件是否可以连接上数据库
2、你的insert语句是否真的可以执行
如果在SQL命令中包含有变量怎么写?比如:
comm.CommandText="INSERT news (title,content) VALUES (name.Text,psw.Text)";我要将两个TextBox的值直接写入数据库那SQL语句怎么写?