here i am using sqlite data base .and code for this are here:
using (SQLiteCommand cmd = new SQLiteCommand(query, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText =
"insert into users(name, password, priviledges) values(" +
"'" + UsernameText.Text.Trim() + "', " + "'" +
QuickMethods.MD5(PasswordText.Password.Trim()) + "', " + "524287" + ")";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO company VALUES('name','" + CompanyName.Text.Trim() + "');";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO company VALUES('address','" + CompanyAddress.Text.Trim() + "');";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO company VALUES('phone','" + CompanyPhone.Text.Trim() + "');";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO company VALUES('email','" + CompanyEmail.Text.Trim() + "');";
cmd.ExecuteNonQuery();
conn.Close();
}
I got exception at line cmd.ExecuteNonQuery() how to solve it.
Your first
cmd.ExecuteNonQuery();is the culprit. The one below connection opening.I think it gives error there because command is not set till that time. Comment it and it should fine.
EDIT
If that did not work
there can be 2 reasons for this problem.
First – connection is made to the right database but there is no such table there.
Second – connection is made to the wrong database. In such case it gives no error. It makes a database file at the specified location. Even Opens the database. But gives this error when fetching/updating data. In such case the specified location will contain a database of 0 KB.
My Answer to this question will help you
Note/Warning related to question, not related to answer:
Always be aware of SQL Injection. Use Parameterised Query (the one with @).
More on SQL Injection