当INSERT INTO
命令到达cmd.ExecuteNonQuery
.
重要的是我使用string.Format
,并且结构尽可能接近当前结构。
{
OleDbConnection con = DAL.GetConnection();
con.Open();
if (con.State == ConnectionState.Open)
{
string s = string.Format("INSERT INTO DataTable1 (Username, Password, FName, LName, Bdate, Sex, City, Mail) VALUES ('{0}', '{1}', '{2}', '{3}', #{4}#, {5}, {6}, '{7}')", uname, pass, fname, lname, bd, sex, city, mail);
OleDbCommand cmd = DAL.GetCommand(con, s);
int check = cmd.ExecuteNonQuery();
if (check == 0)
{
con.Close();
Response.Redirect("Reg.aspx?err=-An error has occured. Please try again-");
}
谢谢你。