List<string> list=new List<string>();
SqlCommand cmd = new SqlCommand("select AC_NAME,AC_NO from PGM_MAST where AGENT_NO=" + txt_Agnt.Text + "", con);
dr = cmd.ExecuteReader();
for ( j=0; j < dr.FieldCount; j++)
txt_AC_Name.Text = list.ToString();
Using it shows only two records. But if I want to retrive more than two records from database then, what may I do? Give me a solution...
21 Dec '12 - 18:32
21 Dec '12 - 20:12
No, it is returning one row: the one that contains the AGENT_NO that matches the contents of the txt_Agnt text box. It adds two values to your table because you return two columns in your query: AC_NAME and AC_NO which are each added in your for loop.
If you want more records, then you need to broaden your search scope by altering your WHERE clause.
But don't do it like that! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
21 Dec '12 - 21:22
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)