如何在Windows应用程序中更新dataGridview控件的列。
我正在使用C#2.0和SQL Server 2005开发Windows窗体应用程序。在我的应用程序中,我通过单击数据库中的btnLoadData按钮将数据检索到dataGridview控件中。用于检索数据的代码示例: -
private void btnLoadData_Click(object sender,EventArgs e)
{
string s1 =select * from Sales_Details ;
SqlConnection cn = new SqlConnection(Class1.cs);
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(s1 ,cn);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables [0];
cn.Close();
}
我想通过点击列来更新或编辑该dataGridview的列并使用相同的ID将其保存回数据库。但我不知道该怎么做,请有人帮帮我。
I m developing a Windows Form Application by using C# 2.0 and SQL Server 2005. In my application, I retrieve data by clicking a btnLoadData button from the database into a dataGridview contrl. Code sample to retrieve data:-
private void btnLoadData_Click(object sender, EventArgs e)
{
string s1 = "select * from Sales_Details";
SqlConnection cn = new SqlConnection(Class1.cs);
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(s1, cn);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
cn.Close();
}
I want to update or edit a column of that dataGridview by clicking the column and save it back to the database by using the same ID. But I don't know how to do this, please someone help me.
这些肯定对你有帮助..
在DataGridView中使用分页添加,编辑和删除 [ ^ ]
数据库更新 - 来自datagridview / [ ^ ]
插入-删除更新管理记录 - 进入 - 数据库使用-datagridview的功能于视觉-C [ ^ ]
These will definitely help you..
Add, Edit, and Delete in DataGridView with Paging[^]
Database-updation-from-datagridview/[^]
Insert-deleting-updating-records-into-database-using-datagridview-in-visual-c[^]
在此尝试:自动保存DataGridView行到SQL Server数据库 [ ^ ]
这不是一篇新文章,但它涵盖了您正在使用的技术:.NET 2和SQL 2005
Try here: Auto Saving DataGridView Rows to a SQL Server Database[^]
It's not a new article, but it covers the technology you are using: .NET 2 and SQL 2005