我将问题列入清单.... [英] im facing the problem into list....

查看:73
本文介绍了我将问题列入清单....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

List<string> list=new List<string>();// declered the list

// fetch data from the database...
 con.Open();
            SqlCommand cmd = new SqlCommand("select AC_NAME,AC_NO from PGM_MAST where AGENT_NO=" + txt_Agnt.Text + "", con);
            SqlDataReader dr; 
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                for ( j=0; j < dr.FieldCount; j++)
                {
                    list.Add(dr[j].ToString());
                    
                }

                txt_AC_Name.Text = list[0].ToString();
                txt_AC.Text= list[1].ToString();
                j++;
                 
               
            }
            dr.Close();
            con.Close();  





使用它只显示两条记录。但是如果我想从数据库中检索两个以上的记录那么,我该怎么办?给我一个解决方案...



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...

推荐答案

不,它返回一行:包含与txt_Agnt文本框内容匹配的AGENT_NO的行。它会为您的表格添加两个值,因为您在查询中返回两列:AC_NAME和AC_NO,它们分别在for循环中添加。



如果您想要更多记录,那么你需要通过改变你的WHERE子句来扩大你的搜索范围。



但是不要这样做!不要连接字符串以构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。
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.


这篇关于我将问题列入清单....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆