I'm using a Windows Forms app (which I'm building) and I'm trying to execute a SQL query (using the SqlCe
class), and although I get a message that a row has been affected (insert), when I try to view the table data it's empty.
Here's my code:
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");
}
}
}
}
What am I doing wrong?
Thanks in advance!