Encountered with a problem... maybe something in the syntax of the query, and the compiler doesn't throw any Exception. But the table do not receive information.
Anything you noticed that maybe wrong?
OleDbConnection conn;
OleDbCommand cmd;
public Commands(OleDbConnection con)
{
conn = con;
}
public Commands()
{
conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DB.accdb");
}
public void node_Join(int id, byte[] mac)
{
try
{
conn.Open();
cmd = new OleDbCommand(@"INSERT INTO Nodes ([J_ID],[Node ID],[Node MAC],[Line Quality],[Status]) values('" + Convert.ToString(id) + @"',0,'" + BitConverter.ToString(mac) + @"',0,'Join')", conn);
cmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception exc)
{
conn.Close();
MessageBox.Show(exc.Message.ToString());
}
}
Convert.ToString(id)andBitConverter.ToString(mac)? Why do you think you should have theseCommandsmethods? What are the types of your columns? And you should always useparameterized queries. This kind of string concatenations are open forSQL Injectionattacks.