c# - Filling a gridview with data from database -
i have report screen 6 textboxes. check checkboxes , data in database sql query. when click on button generate report, doesn't show data in gridview. pasted gridview toolbox screen , want fill c# code , sql command. missing something?
protected void button1_click(object sender, eventargs e) { connect = new sqlconnection(@"data source=lp12;initial catalog=smmsdata;integrated security=true"); connect.open(); sqlcommand cmd = new sqlcommand(); cmd.connection = connect; cmd.commandtext = "select druksensor, flowsensor, tempsensor, kwaliteitsensor, toerental, olieverbruik" + " systeemsensorinfo" + " druksensor=@druksensor" + " , flowsensor=@flowsensor" + " , tempsensor=@tempsensor" + " , kwaliteitsensor=@kwaliteitsensor" + " , toerental=@toerental" + " , olieverbruik=@olieverbruik" ; cmd.parameters.add("@druksensor", sqldbtype.bit); cmd.parameters.add("@flowsensor", sqldbtype.bit); cmd.parameters.add("@tempsensor", sqldbtype.bit); cmd.parameters.add("@kwaliteitsensor", sqldbtype.bit); cmd.parameters.add("@toerental", sqldbtype.bit); cmd.parameters.add("@olieverbruik", sqldbtype.bit); cmd.parameters["@druksensor"].value = checkboxdruk.checked; cmd.parameters["@flowsensor"].value = checkboxflow.checked; cmd.parameters["@tempsensor"].value = checkboxtemp.checked; cmd.parameters["@kwaliteitsensor"].value = checkkwaliteit.checked; cmd.parameters["@toerental"].value = checkboxtoerental.checked; cmd.parameters["@olieverbruik"].value = checkboxolieverbruik.checked; dataset ds = new dataset(); new sqldataadapter(cmd).fill(ds); gridview1.datasource = ds.tables[0]; gridview1.autogeneratecolumns = true; }
you have not binded data
gridview
. bind data gridview using databind
gridview1.datasource = ds.tables[0]; gridview1.databind();
Comments
Post a Comment