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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -