asp.net - How can i attach my datasource from the database inside a gridview? -
i`m making mumbai local train timings project class project.. how can attach datasource database inside gridview??
sqlcommand cmd; protected void page_load(object sender, eventargs e) { } protected void button1_click(object sender, eventargs e) { con.open(); cmd = new sqlcommand("select * @d where(select * @c source = @a , destination = @b)",con); cmd.parameters.addwithvalue("@d", dropdownlist3.selectedvalue); cmd.parameters.addwithvalue("@c",dropdownlist3.selectedvalue); cmd.parameters.addwithvalue("@a",dropdownlist1.selectedvalue); cmd.parameters.addwithvalue("@b",dropdownlist2.selectedvalue); //int = cmd.executenonquery(); //if (i > 0) //{ gridview1.datasource = //what shud put here in datasource?? gridview1.databind(); //} }
just thing this:
con.open(); sqlcommand cmd = new sqlcommand("select * @d where(select * @c source = @a , destination = @b)",con); cmd.parameters.addwithvalue("@d", dropdownlist3.selectedvalue); cmd.parameters.addwithvalue("@c",dropdownlist3.selectedvalue); cmd.parameters.addwithvalue("@a",dropdownlist1.selectedvalue); cmd.parameters.addwithvalue("@b",dropdownlist2.selectedvalue); sqldataadapter adapt = new sqldataadapter(); datatable dt = new datatable(); adapt.selectcommand = cmd; adapt.fill(dt); gridview gridview1 = new gridview(); gridview1.datasource = dt; gridview1.databind();
then link might helpful : the c# station ado.net tutorial
best regards
Comments
Post a Comment