Click here to Skip to main content
14,971,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to set number of rows i want to fetch from database to listbox.
on button click ,10 items i want to display to itembox from column[0]. how can i specify number of itemz ??

What I have tried:

string query = " select MonoCode,MonoCode_Result,MasterCode,OuterCode,PalletCode from BatchDetails Where MonoCode_Result = 1 and MasterCode IS NULL "
"and OuterCode IS NULL and PalletCode IS NULL ";
using (SqlCommand sqlCommand = new SqlCommand(query, sqlConn))
{
// sqlCommand.Parameters.AddWithValue("@MonoCode", textBox1.Text);
sqlCommand.Parameters.AddWithValue("@MonoCode_Result", 1);
sqlCommand.Parameters.AddWithValue("@OuterCode", "NULL");
sqlCommand.Parameters.AddWithValue("@MaterCode", "NULL");
sqlCommand.Parameters.AddWithValue("@PalletCode", "NULL");

SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

var dataReader = sqlDataReader;

while(dataReader.Read())
{

}
Posted
Updated 29-May-21 0:58am
Comments
Member 15212425 29-May-21 7:08am
   
the limit is user input data stored in app.config. respective to that number , i want to display data to listbox .

1 solution

Use the SELECT TOP n option as described at SQL SELECT TOP, LIMIT, FETCH FIRST ROWS ONLY, ROWNUM[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900