我正在使用Windows窗体应用程序(我正在构建)并且我正在尝试执行SQL查询(使用SqlCe
类),尽管我收到一条消息,表明已经有一行受影响(插入),当我尝试查看表数据时它是空的。
这是我的代码:
string ifNotExists = String.Format("SELECT * FROM users WHERE username='{0}' OR email_addr='{1}' OR phone_num='{2}'", username, email_addr, phone_num);
using (SqlCeCommand cmd = new SqlCeCommand(ifNotExists, s))
{
SqlCeDataReader reader = cmd.ExecuteReader();
if (!reader.Read())
{
//can proceed
string reg_cmd = String.Format("INSERT INTO users(username, password, email_addr, phone_num) VALUES('{0}', '{1}', '{2}', '{3}')", username, password, email_addr, phone_num);
using (SqlCeCommand reg_cmd_cmd = new SqlCeCommand(reg_cmd, s))
{
int a = reg_cmd_cmd.ExecuteNonQuery();
if (a == 1)
{
MessageBox.Show("It went through successfully!");
}
else
{
MessageBox.Show("Some error occured");
}
}
}
}
我做错了什么?
提前致谢!