c# - Can Someone explain meaning of this exception? Connection String, Table Name, query syntax are correct -
sqlcecommand cmd = new sqlcecommand("insert tbl_astatus (asset status,remarks) values (@a, @b)", login.sqlconn); cmd.parameters.addwithvalue("@a", txtassetstatus.text); cmd.parameters.addwithvalue("@b", txtremarks.text); int = cmd.executenonquery(); messagebox.show(a.tostring());
exception shown:
there error parsing query. [ token line number = 1,token line offset = 32,token in error = status ]
if table name or column names includes white space, need use them square brackets [asset status]
. not recommended. better changing column name else if can.
read: database, table , column naming conventions?
also use using
statement dispose database connections , objects.
using(sqlcecommand cmd = login.sqlconn.createcommand()) { cmd.commandtext = "insert tbl_astatus ([asset status],remarks) values (@a, @b)"; cmd.parameters.add("@a", sqldbtype.nvarchar).value = txtassetstatus.text; cmd.parameters.add("@b", sqldbtype.nvarchar).value = txtremarks.text; // assume column types nvarchar login.sqlconn.open(); int = cmd.executenonquery(); messagebox.show(a.tostring()); }
and don't use addwithvalue
method. may generate unexpected results sometimes. use sqlparametercollection.add
method , it's overloads.
Comments
Post a Comment