c# - ASP.Net MySqlDatabase Null Value -
i have below code in asp.net web forms page c#,
protected void page_load(object sender, eventargs e) { conn.open(); string selecttruckquery = "select * truck truck_id='" + truckid + "'"; mysqlcommand cmd = new mysqlcommand(selecttruckquery, conn); foreach (dbdatarecord rowdata in cmd.executereader()) { if (!rowdata.isdbnull(rowdata.getordinal("truck_id"))) idno.text = rowdata.getstring(rowdata.getordinal("truck_id")); if (!rowdata.isdbnull(rowdata.getordinal("registration_no"))) registrationno.text = rowdata.getstring(rowdata.getordinal("registration_no")); if (!rowdata.isdbnull(rowdata.getordinal("make"))) tmake.text = rowdata.getstring(rowdata.getordinal("make")); if (!rowdata.isdbnull(rowdata.getordinal("model"))) tmod.text = rowdata.getstring(rowdata.getordinal("model")); if (!rowdata.isdbnull(rowdata.getordinal("engine_no"))) teng.text = rowdata.getstring(rowdata.getordinal("engine_no")); if (!rowdata.isdbnull(rowdata.getordinal("chassis_no"))) tchass.text = rowdata.getstring(rowdata.getordinal("chassis_no")); if (!rowdata.isdbnull(rowdata.getordinal("driver_name"))) tdriver.text = rowdata.getstring(rowdata.getordinal("driver_name")); if (!rowdata.isdbnull(rowdata.getordinal("driver_contact_no"))) tno.text = rowdata.getstring(rowdata.getordinal("driver_contact_no")); if (!rowdata.isdbnull(rowdata.getordinal("status"))) tstat.text = rowdata.getstring(rowdata.getordinal("status")); } conn.close(); }
i want values mysqldatabase, getting values null
mysqldatabase, i'm quite sure code correct.
all output null, supposed problem of this?
please me!
you can use parameterised query.
please try below.
conn.open(); string selecttruckquery = "select * truck truck_id=@truckid"; mysqlcommand cmd = new mysqlcommand(selecttruckquery, conn); cmd.parameter.addwithvalue("@truckid", truckid);
convert truckid depending on datatype of field.
Comments
Post a Comment