March 31st, 2014, 12:48 AM
Attempted to read or write protected memory.
I have two from in visual studio 2010 with C#.
In form1 I have one combobox and one button .In form2 I have Reportviewer . When Button in form1 is clicked form2 is shown. Now my problem is when I click button to show form2 on the line Form2.Show(); this error appear :
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
What can i do?
In form1 I have one combobox that combo fill with Database with this code in the Form Load:
private void DocReportOnlyAlalhesabSearch_Load(object sender, EventArgs e)
//fill shahrestan Combo
if (Class.Global.CurrentYear.Length != 0)
cmd1 = new OleDbCommand();
string connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|" + "\\DB\\" + Class.Global.CurrentYear;
conn1 = new OleDbConnection(connectionstring);
cmd1.CommandType = CommandType.Text;
cmd1 = new OleDbCommand("SELECT * From tblShahrestanName ;", conn1);
OleDbDataReader myreader = cmd1.ExecuteReader();
countrow = 0;
countrow = countrow + 1;
catch (Exception Ar)
//end fill shahrestan combo
In a button click on the form1 I have this code :
private void btnSearch_Click(object sender, EventArgs e)
Form2 Form2 = new Form2();
In form2 I have A report viewer in form load of that I have this code:
private void Form2_Load(object sender, EventArgs e)
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|" + "\\DB\\" + Class.Global.CurrentYear);
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * from DocReportAlalhesabJoda", con);
DataSet ds = new DataSet();
ds.Tables.TableName = "DataTableDocReportAlalhesabJoda";
reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", ds.Tables));
April 14th, 2014, 06:53 PM
Re: Attempted to read or write protected memory.
You cannot d this. as yu have the same Name for the class and the variable.
Form2 Form2 = new Form2();
You Need to write someting like
Form2 frm = new Form2();
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!