Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two separate forms. One is for input data and the other is datagridview to display the imputs. I want the input to be displayed in the datagridview but I having error. The error is "EdificationMembersdataGridview does not exist in the current context"

Please I need help

What I have tried:

I tried the one in which the form and the datagriveiw are in the same windowsform it worked. But this one the form and the datagridview are in separate windows.
The form is a submenu item and the datagridview is also a submenu item.





SqlConnection con = new SqlConnection("Data Source=DESKTOP-JV7URL6;Initial Catalog=COCAhenkroApp;Integrated Security=True");
       private void btnSave_Click(object sender, EventArgs e)
       {

           con.Open();
           SqlCommand command = new SqlCommand("insert into EdificationMembers values('" + txtName.Text + "','" + cmbPosition.Text + "','" + txtContact.Text + "',getdate())", con);
           command.ExecuteNonQuery();
           MessageBox.Show("Successfully Saved");
           con.Close();
           BindData();
       }
       void BindData()
       {
           SqlCommand command = new SqlCommand("select * from EdificationMembers", con);
           SqlDataAdapter sda = new SqlDataAdapter(command);
           DataTable dt = new DataTable();
           sda.Fill(dt);
           EdificationMembersdataGridView.DataSource = dt;


       }
Posted
Updated 23-Mar-23 9:20am

The answer lies in your explanation. You want to "share" the data between two views/windows - ie: two seperate "instances". You need to set up a common class (Service) that both instances can "share". For your needs, a Singleton/static class will do the trick.

Lastly, it is best practice not to hard code your SQL connection string in your app. You should be storing externally, typically in the app.config file.
 
Share this answer
 
C# is case-sensitive, so "EdificationMembersdataGridView" is not the same as "EdificationMembersDataGridView". Notice the "D" is not capitalized. So if your actual datagrid control name is different from "EdificationMembersdataGridView" by even a single letter due to capitalization, you're going to get that error message.
 
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