Using SQL Between Query and Showing all results in ASP.NET C# -
this sample code check data on table1 using 2 filters, column1 , between data in column2. code have working getting 1 result. example. enter "1" in textbox1, "3" in textbox2 , "6" in textbox3. select * table1 column1 = '1' , column2 between '3' , '6'
-- when run in sql result 3,4,5,6 in c# getting "6". can me "3,4,5,6" result. thank you.
public partial class webform1 : system.web.ui.page { sqlconnection sc; sqlcommand cmd; sqldatareader dr; protected void page_load(object sender, eventargs e) { } protected void button1_click(object sender, eventargs e) { sc = new sqlconnection(configurationmanager.connectionstrings["babbler"].connectionstring); sc.open(); cmd = new sqlcommand("select * table1 column1= '" + textbox1.text + "' , column2 between '" + textbox2.text + "'" + " , " + "'" + textbox3.text + "'", sc); dr = cmd.executereader(); if (dr.hasrows) { while (dr.read()) { label1.text = dr["column2"].tostring(); } } } }
}
your loop not appending values, rather overwriting label1. change while loop
while (dr.read()) { label1.text += dr["column2"].tostring() + ","; } if (label1.text.endswith(",")) label1.text = label1.text.substring(0, label1.text.length-1) //remove last comma
Comments
Post a Comment