c# - Data type mismatch -
i got error when tried select userid database datatable. first userid autonumber, second userid number, , database ms access db.
private void () { odbcdataadapter ad = new odbcdataadapter("select userid userinfo badgenumber='" + userid + "'", this.fm.cn); datatable t = new datatable(); ad.fill(t); ad.dispose(); if (t.rows.count > 0) { odbccommand cmd = new odbccommand(); cmd.connection = this.fm.cn; string id = t.rows[0][0].tostring(); //check date odbcdataadapter add = new odbcdataadapter("select userid checkinout userid='" + id + "'", this.fm.cn); datatable tc = new datatable(); add.fill(tc); // <- gotta error here. add.dispose(); } }
change query to:
"select userid checkinout userid=" + id
in sql queries, strings literals (or chars) required enclosed within pair of single quotes '
, used delimiter string. delimiter pretty character used identify boundaries - in case of string, single quotes specify string starts , ends.
because of nature of numbers (integers example), not necessary indicate delimiter such single quotes. code failing because when database engine saw single quotes, expecting string, column number datatype, , why obtained data type mismatch error when executing query.
Comments
Post a Comment