Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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;
            }
Posted 22-Feb-13 3:56am
Edited 22-Feb-13 3:59am
RyanDev108.8K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
  Permalink  

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

  Print Answers RSS
0 Maciej Los 245
1 OriginalGriff 210
2 Manfred R. Bihy 190
3 CHill60 180
4 _Amy 155
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,157
2 Maciej Los 3,774
3 Peter Leow 3,448
4 CHill60 2,702


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100