I get this error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
When running this code:
namespace ProjectInterface
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); -exception unhandled(error)!!!!
}
}
}
When I search a subject name from the database .
Here my textbox code:
private void txtSubject_TextChanged(object sender, EventArgs e)
{
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT SubjectName From databse.subject WHERE SubjectName LIKE @name", con);
cmd.Parameters.Add(new MySqlParameter("@name", "%" + txtSubject.Text + "%"));
MySqlDataReader dr = cmd.ExecuteReader();
AutoCompleteStringCollection subjectColl = new AutoCompleteStringCollection();
while (dr.Read())
{
subjectColl.Add(dr.GetString(0));
}
txtSubject.AutoCompleteCustomSource = subjectColl;
con.Close();
}
Sometimes it is OK to run, but it often shows this error. How do I solve it?