求C#向ACCESS数据库插入数据的SQL语句 急急急!!!!那位大虾帮下忙
各位高手是不是拼SQL语句的字符串错了啊 , ,
我想向access的reader表中插入一条记录
表reader的结构为 :
readerID(主键) 文本
readerName 文本
readerPassword 文本
readerPhone 文本
readerStartTime 时间/日期 只有这个允许空
主要的代码如下:
using SDO = System.Data.OleDb;
string sConncet = string.Format("Provider={0};Data Source={1}{2}", "Microsoft.Jet.OLEDB.4.0;", System.AppDomain.CurrentDomain.BaseDirectory, "Library.mdb");
SDO.OleDbConnection dbConn = null;
dbConn = new SDO.OleDbConnection(sConncet);
dbConn.Open();
SDO.OleDbCommand dbCmd;
string sql;
public void createCmd(string table, string rID, string rname, string rpwd, string rphone)
{
sql = "insert into" + " " + table + " " + "values" + "(" + "'" + rID + "'" + "," + "'" + rname + "'" + "," + "'" + rpwd + "'" + "," + "'" + rphone + "'" + "," + "'" + DateTime.Now + "'" + ")" + " " + "go";
}
dbCmd = new SDO.OleDbCommand(sql, dbConn);
dbConn.Close();
------解决方案--------------------SQL code
sql = "insert into " + table + "(readerID,readerName ,readerPassword ,readerPhone ,readerStartTime ) values('" + rID + "','" + rname + "','" + rpwd + "','" + rphone + "','" + DateTime.Now.ToString() + "')";
------解决方案--------------------
dbCmd的执行没有啊,execute的语句呢?除了时间,其他字段不为空,那么给每个参数加上判空处理IsNullorEmpty()