| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 681 人关注过本帖
标题:数据库查询问题
只看楼主 加入收藏
zllkiller
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-11-30
收藏
 问题点数:0 回复次数:3 
数据库查询问题
写了个数据库查询问题,碰到很大麻烦,求救

做了一个数据库查询的程序
主要功能:
直接在TEXT中填入要查询的数据查询,或者从文件中读取一堆数据查询

我是把文件中的所有数据放到一个数组中
判断TEXT中有没输入,如果有输入,就查询TEXT中的,如果没有输入,就查询数组中的
循环数组中的所有数据,每条都查询一次,然后放到输出里

目前碰到的问题,查询TEXT的很快,基本上几秒就出结果
但是查询文件中的,就会很久,基本上要3分钟以上才会出结果。。。
文件中也只有一个数据。。。

请问这个是什么原因。。。
搜索更多相关主题的帖子: 数据库 查询 
2008-11-30 21:52
zllkiller
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-11-30
收藏
得分:0 
代码如下:
        public string[] shuju =new string[9999];
        public string Getread(string cha, string search)
        {
            string shuchu="";
             id from reg where "+cha+"='" + search + "'";
            SqlDataReader thisreader = thiscommand.ExecuteReader();
            while (thisreader.Read())
            {
                shuchu+=thisreader["id"];
            }
            thisreader.Close();
            return shuchu;
        }




        private void button1_Click(object sender, EventArgs e)
        {

                string output="";

                if ((this.shuru.Text.Length == 0) && (shuju[0] == null))
                {
                    MessageBox.Show("请输入要查询的信息或者读取文件中的信息");
                    return;
                }
                else
                {
                    SqlConnection thisconnection = new SqlConnection(qu());
                    try
                    {
                        thisconnection.Open();
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("数据库连接失败,请联系管理员");
                        Application.Exit();
                    }

                    thiscommand = thisconnection.CreateCommand();

                    if (shuru.Text.Length != 0)
                    {
                        output += Getread(cha(), this.shuru.Text) + "\r\n";

                    }
                    else
                    {
                        for (int x=0;x<daxiao;x++)
                        {
                            output += Getread(cha(), shuju[x]) + "\r\n";
                        }
                    }

                    thisconnection.Close();
                    this.shuru.Text = null;
                    this.textBox1.Text = output;
                }

        }


        private void duwenjian()
        {
            string chaxun;
            try
            {

                FileStream wenjian = new FileStream("chaxun.txt", FileMode.Open);
                StreamReader cha = new StreamReader(wenjian,System.Text.Encoding.GetEncoding("gb2312"));
                chaxun = cha.ReadLine();

                while (chaxun != null)
                {
                    for (int x = 0; x <= shuju.GetUpperBound(0); x++)
                    {

                        chaxun = cha.ReadLine();
                        shuju[x] = chaxun;
                        daxiao++;
                    }
                }
                MessageBox.Show("文件读取成功!");
                cha.Close();
            }
            catch (IOException e)
            {
                MessageBox.Show(e.ToString());
            }
            catch (SystemException)
            {
                MessageBox.Show("文件读取失败,请确认chaxun.txt在当前目录中");
            }

        }
2008-11-30 21:55
从小到大
Rank: 1
等 级:新手上路
威 望:2
帖 子:200
专家分:0
注 册:2006-6-24
收藏
得分:0 
string chaxun="";
            try
            {

                FileStream wenjian = new FileStream("chaxun.txt", FileMode.Open);
                StreamReader cha = new StreamReader(wenjian,System.Text.Encoding.GetEncoding("gb2312"));
               
                while (chaxun != null)
                {
                    chaxun = cha.ReadLine();
                    for (int x = 0; x <= shuju.GetUpperBound(0); x++)
                    {

                        chaxun = cha.ReadLine();
                        shuju[x] = chaxun;
                        daxiao++;
                    }
                }
                MessageBox.Show("文件读取成功!");
                cha.Close();
            }
这样看行不?

2008-12-01 17:06
zllkiller
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-11-30
收藏
得分:0 
我已经找到问题了。。。循环的时候参数有问题,所以一直在循环,会循环9999次,所以很慢。
2008-12-01 17:47
快速回复:数据库查询问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014210 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved