C#中 winform dataGridview 如何写入数据库?mdf文件。下面是代码和保存按钮下的代码
privatestudent_dbmlDataContextdatabase=newstudent_dbmlDataContext();privatevoidstuden...
private student_dbmlDataContext database = new student_dbmlDataContext();
private void studentBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
Validate();
studentBindingSource.EndEdit();
database.SubmitChanges();
}
求linq高手 展开
private void studentBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
Validate();
studentBindingSource.EndEdit();
database.SubmitChanges();
}
求linq高手 展开
展开全部
//连接数据库
static string str = "server=(local);database=saleDB;integrated security=true";
SqlConnection conn = null;
SqlCommand comm = null;
//创建一个适配器
SqlDataAdapter da;
private void btnShow_Click(object sender, EventArgs e)
{
conn = new SqlConnection(str);
//SQL语句
comm = new SqlCommand("SELECT * FROM productInfo", conn);
//读取数据库中的文件,然后写入da中
da = new SqlDataAdapter(comm);
//在内存中创建一个临时的表table
DataTable table = new DataTable();
//读取数据库,填充表
da.Fill(table);
dataGridView的文件源DataSource为那个临时表table
this.dataGridView.DataSource = table;
}
static string str = "server=(local);database=saleDB;integrated security=true";
SqlConnection conn = null;
SqlCommand comm = null;
//创建一个适配器
SqlDataAdapter da;
private void btnShow_Click(object sender, EventArgs e)
{
conn = new SqlConnection(str);
//SQL语句
comm = new SqlCommand("SELECT * FROM productInfo", conn);
//读取数据库中的文件,然后写入da中
da = new SqlDataAdapter(comm);
//在内存中创建一个临时的表table
DataTable table = new DataTable();
//读取数据库,填充表
da.Fill(table);
dataGridView的文件源DataSource为那个临时表table
this.dataGridView.DataSource = table;
}
参考资料: 用SQL
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询