为什么数据存不到access2003中,显示的exception是insert into 语句出现错误.帮帮忙!(做的一个注册页面)
这以下是后台c# 程序.望指正.
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;data source=E:\\PersonalWebPage\\App_Data\\diary.mdb ";
OleDbConnection conn = new OleDbConnection(strConnection);
string strSQL = "insert into userreg(username,password,name,email,gender,QQ) values(@username,@password,@name,@email,@gender,@QQ ) ";
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add( "@username ", OleDbType.VarChar, 50);
cmd.Parameters.Add( "@password ", OleDbType.VarChar, 50);
cmd.Parameters.Add( "@name ", OleDbType.VarChar, 50);
cmd.Parameters.Add( "@email ", OleDbType.VarChar,50);
cmd.Parameters.Add( "@gender ",OleDbType.VarChar,50);
cmd.Parameters.Add( "@QQ ", OleDbType.VarChar, 50);
cmd.Parameters[ "@username "].Value = username.Text.ToString();
cmd.Parameters[ "@password "].Value = password.Text.ToString();
cmd.Parameters[ "@name "].Value = name.Text.ToString();
cmd.Parameters[ "@email "].Value = email.Text.ToString();
cmd.Parameters[ "@gender "].Value = rblsex.SelectedItem.Value.ToString();
cmd.Parameters[ "@QQ "].Value = qq.Text.ToString();
try
{
conn.Open();
cmd.ExecuteNonQuery();
Response.Redirect( "Default.aspx ");
}
catch(Exception ex)
{
message.Text = ex.Message.ToString();
}
finally
{
conn.Close();
}
[解决办法]
access中用?不象oracle
string strSQL = "insert into userreg(username,password,name,email,gender,QQ) values(?,?,?,?,?,?) ";
== 思想重于技巧 ==
[解决办法]
另外注意数据类型匹配
== 思想重于技巧 ==