I want to add new admin into my database. But it doesn't work it. Please look at the button1_Click event handler, I need to add value in this event.
public partial class Form1 : Form
{
protected NetTanitimTestEntities adminNameContext;
public Form1()
{
InitializeComponent();
adminNameContext = new NetTanitimTestEntities();
}
private void Form1_Load(object sender, EventArgs e)
{
ObjectQuery<Admins> adminNameQuery = adminNameContext.Admins;
dataGridView1.DataSource = adminNameQuery;
dataGridView1.Columns["id"].Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
using (NetTanitimTestEntities newadmin = new NetTanitimTestEntities())
{
Admins admin = new Admins { Name = "ali", SurName = "Çorlu", Username = "acorlu", Password = "1234", UserType = "user" };
newadmin.SaveChanges();
}
}
private void button2_Click(object sender, EventArgs e)
{
adminNameContext.SaveChanges();
}
}