我想將新的admin添加到我的數據庫中。但它不起作用。請看button1_Click事件處理程序,我需要在這個事件中增加值。ADO.NET實體框架SaveChanges()不起作用
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();
}
}
當您重新啓動程序時,Button1添加的新行顯示yup嗎? – 2009-06-13 11:11:50