如何在Windows窗体中搜索谷歌等数据/文本? [英] how to search data/text like google in Windows Form?

查看:87
本文介绍了如何在Windows窗体中搜索谷歌等数据/文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!!我想在Windows窗体中搜索谷歌等数据/文本。我已经在MS-Access数据库中保存了一些文本,我想在windows窗体的textBox中搜索那些数据/文本。我已启用textBox的AutoCompleteMode = Suggest,AutoCompleteCustomSource = CustomSource。但有时它会向我显示错误尝试读取或写入受保护的内存。这通常表明其他内存已损坏。请解决我的问题。谢谢........

Hello!! I want to search data/text like google in windows form. I have saves some text in MS-Access database and i want to search those data/texts in textBox of windows form. I have enabled "AutoCompleteMode=Suggest","AutoCompleteCustomSource=CustomSource" of the textBox. But sometimes it shows me an error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Please solve my problem. Thanks........

try
            {
                cn.Open();
                AutoCompleteStringCollection acs = new AutoCompleteStringCollection();
                OleDbCommand cm = new OleDbCommand("select itemname from purchaseitem", cn);
                OleDbDataAdapter da = new OleDbDataAdapter(cm);
                OleDbDataReader dr = cm.ExecuteReader();
                if (dr.HasRows == true)
                {
                    while (dr.Read())
                        acs.Add(dr["itemname"].ToString());
                }
                txt_itemname.AutoCompleteCustomSource = acs;
                dr.Close();
                cn.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }

推荐答案

StringBuilder sb = new StringBuilder();



//用于每次读取操作

byte [] buf = new byte [8192];

string GS =http://google.com/search ?q =;

//准备我们要求的网页

HttpWebRequest request =(HttpWebRequest)WebRequest.Create(GS);



//执行请求

HttpWebResponse response =(HttpWebResponse)request.GetResponse();



//我们将通过响应流读取数据

流resStream = response.GetResponseStream();

string tempString = null;

int count = 0;

do

{

//用数据填充缓冲区

count = resStream。 [R ead(buf,0,buf.Length);

//确保我们读取一些数据

if(count!= 0)

{

//从字节转换为ASCII文本

tempString = Encoding.ASCII.GetString(buf,0,count);



//继续构建字符串

sb.Append(tempString);

}

}

while(count> 0);
StringBuilder sb = new StringBuilder();

// used on each read operation
byte[] buf = new byte[8192];
string GS = "http://google.com/search?q=";
// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(GS);

// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

// we will read data via the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);

// continue building the string
sb.Append(tempString);
}
}
while (count > 0);


这篇关于如何在Windows窗体中搜索谷歌等数据/文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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