I am not able to fetch single record from access database in C#.Net -
i doing project on library management system. want fetch data student using borrower number select query. code not working giving exception type mismatch in criteria expression @ line number 40 dadapter.fill(datatable);. please me. here code. thank :)
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.data.oledb; namespace librarymanagment { public partial class viewstudent : form { private oledbconnection bookconn; private oledbcommand oledbcmd = new oledbcommand(); //parameter mdsaputra.udl private string connparam = @"provider=microsoft.jet.oledb.4.0;data source=e:\mini\database\library.mdb;persist security info=false"; public viewstudent() { bookconn = new oledbconnection(connparam); initializecomponent(); } private void btnview_click(object sender, eventargs e) { datagridview1.datasource = null; datagridview1.rows.clear(); datagridview1.refresh(); oledbdataadapter dadapter = new oledbdataadapter("select * student borrowerno = '"+ this.txtborrowerno.text +"';", connparam); oledbcommandbuilder cbuilder = new oledbcommandbuilder(dadapter); datatable datatable = new datatable(); dataset ds = new dataset(); dadapter.fill(datatable); (int = 0; < datatable.rows.count; i++) { datagridview1.rows.add(datatable.rows[i][0], datatable.rows[i][1], datatable.rows[i][2], datatable.rows[i][3], datatable.rows[i][4], datatable.rows[i][5], datatable.rows[i][6], datatable.rows[i][7]); } } private void viewstudent_load(object sender, eventargs e) { // todo: line of code loads data 'librarydataset.student' table. can move, or remove it, needed. // this.studenttableadapter4.fill(this.librarydataset.student); } }
}
from error mentioned in comments, borrower no of type number , seems causing problem.
oledbdataadapter dadapter = new oledbdataadapter("select * student borrowerno = "+ this.txtborrowerno.text +";", connparam);
notice have removed single quotes. use single quotes when data type string.