Record Not Insert
-
please tell me Error in My Coding My Coding Is OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\\Opal Agro Chemical\\OpalAgroChemical.mdb;Uid=;Pwd=;"); string Invqurey = "insert into invoice(id,date,gpno,product,customer,qty,carton,rate,amount,bilty,expdate) values('" + inid.Text + "','" + dt.Text + "','" + gpno.Text + "','" + prod.Text + "','" + cust.Text + "','" + qty.Text + "','" + carton.Text + "','" + rate.Text + "','" + amount.Text + "','" + bilty.Text + "','" + expdate.Text +"')"; OdbcCommand cmd = new OdbcCommand(Invqurey, conn); conn.Open(); MessageBox.Show(cmd.CommandText); cmd.ExecuteNonQuery(); conn.Close(); This Error Is Showing When i Insert Record System.Data.Odbc.OdbcException was unhandled Message="ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement." Source="odbcjt32.dll" ErrorCode=-2146232009 Please Help Me Thanks In Advance Jawad Khatri
-
please tell me Error in My Coding My Coding Is OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\\Opal Agro Chemical\\OpalAgroChemical.mdb;Uid=;Pwd=;"); string Invqurey = "insert into invoice(id,date,gpno,product,customer,qty,carton,rate,amount,bilty,expdate) values('" + inid.Text + "','" + dt.Text + "','" + gpno.Text + "','" + prod.Text + "','" + cust.Text + "','" + qty.Text + "','" + carton.Text + "','" + rate.Text + "','" + amount.Text + "','" + bilty.Text + "','" + expdate.Text +"')"; OdbcCommand cmd = new OdbcCommand(Invqurey, conn); conn.Open(); MessageBox.Show(cmd.CommandText); cmd.ExecuteNonQuery(); conn.Close(); This Error Is Showing When i Insert Record System.Data.Odbc.OdbcException was unhandled Message="ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement." Source="odbcjt32.dll" ErrorCode=-2146232009 Please Help Me Thanks In Advance Jawad Khatri
Get rid of the problem, and potential SQL injection attacks by using Parameterized queries:
string Invqurey = "INSERT INTO invoice (id, date, gpno, product, customer, qty, carton, rate, amount, bilty, expdate)" +
" VALUES (@inid, @dt, @gpno, @prod, @cust, @qty, @carton, @rate, @amount, @bilty, @expdate)";
OdbcCommand cmd = new OdbcCommand(Invqurey, conn);
cmd.AddWithValue("@inid", inid.Text);
cmd.AddWithValue("@gpno", gpno.Text);
...Oh - and the standard is to use UPPERCASE for SQL keywords.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
Get rid of the problem, and potential SQL injection attacks by using Parameterized queries:
string Invqurey = "INSERT INTO invoice (id, date, gpno, product, customer, qty, carton, rate, amount, bilty, expdate)" +
" VALUES (@inid, @dt, @gpno, @prod, @cust, @qty, @carton, @rate, @amount, @bilty, @expdate)";
OdbcCommand cmd = new OdbcCommand(Invqurey, conn);
cmd.AddWithValue("@inid", inid.Text);
cmd.AddWithValue("@gpno", gpno.Text);
...Oh - and the standard is to use UPPERCASE for SQL keywords.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
OriginalGriff wrote:
Oh - and the standard is to use UPPERCASE for SQL keywords.
In every code shop and software house I've been in for over 20 years the standard has always been lower case! Don't want to start an argument, just saying that the real standard is that there are no real standards...
Tychotics: take us back to the moon "Life, for ever dying to be born afresh, for ever young and eager, will presently stand upon this earth as upon a footstool, and stretch out its realm amidst the stars." H. G. Wells
-
please tell me Error in My Coding My Coding Is OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\\Opal Agro Chemical\\OpalAgroChemical.mdb;Uid=;Pwd=;"); string Invqurey = "insert into invoice(id,date,gpno,product,customer,qty,carton,rate,amount,bilty,expdate) values('" + inid.Text + "','" + dt.Text + "','" + gpno.Text + "','" + prod.Text + "','" + cust.Text + "','" + qty.Text + "','" + carton.Text + "','" + rate.Text + "','" + amount.Text + "','" + bilty.Text + "','" + expdate.Text +"')"; OdbcCommand cmd = new OdbcCommand(Invqurey, conn); conn.Open(); MessageBox.Show(cmd.CommandText); cmd.ExecuteNonQuery(); conn.Close(); This Error Is Showing When i Insert Record System.Data.Odbc.OdbcException was unhandled Message="ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement." Source="odbcjt32.dll" ErrorCode=-2146232009 Please Help Me Thanks In Advance Jawad Khatri
get the content onv Invqurey, an ask then the question in the SQL forum.