Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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........
C#
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
Updated 22-Feb-13 3:59am
v2

1 solution

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);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900