如何从datagridview获取数据并将其更新到数据库? [英] How to get the data from datagridview and update it to the database?
本文介绍了如何从datagridview获取数据并将其更新到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个datagridview,显示数据库中记录总数的50%。现在,我需要在tblclass,tblstudentinfo中更新它们的节名。我不知道怎么。有人可以帮帮我吗?
这是我的代码:
p_table1 = new DataTable();
p_table1.Clear();
string questa =SELECT TOP 50%*来自tblStudentInformation,其中GradeLevel ='+ label2.Text +'和Result> = 85且SectionName为IS NULL;
SqlDataAdapter rad = new SqlDataAdapter(questa,conn);
rad.Fill(p_table1);
dataGridView2.DataSource = p_table1;
解决方案
p_table1 = new DataTable();
p_table1.Clear();
string questa =SELECT TOP 50%*来自tblStudentInformation其中GradeLevel ='+ label2.Text +'和Result> = 85且SectionName IS NULL;
SqlDataAdapter rad = new SqlDataAdapter(questa,conn);
rad.Fill(p_table1);
dataGridView2.DataSource = p_table1;
string data =update tblStudentInformation set SectionName ='your update value'where WhereLevel ='+ label2.Text +'且Result> = 85且SectionName IS NULL;
rad = new SqlDataAdapter(data,conn);
rad.Fill(p_table1);
dataGridView2.DataSource = p_table1;
Hi guys.
I have a datagridview that displays the 50 percent of the total number of the records in the database. Now, I need to update their section name in tblclass, tblstudentinfo. I do not know how. Can anyone help me?
Here is my code:
p_table1 = new DataTable(); p_table1.Clear(); string questa = "SELECT TOP 50 Percent * from tblStudentInformation Where GradeLevel ='" + label2.Text + "' and Result >= 85 and SectionName IS NULL"; SqlDataAdapter rad = new SqlDataAdapter(questa, conn); rad.Fill(p_table1); dataGridView2.DataSource = p_table1;
解决方案
p_table1 = new DataTable();
p_table1.Clear();
string questa = "SELECT TOP 50 Percent * from tblStudentInformation Where GradeLevel ='" + label2.Text + "' and Result >= 85 and SectionName IS NULL";
SqlDataAdapter rad = new SqlDataAdapter(questa, conn);
rad.Fill(p_table1);
dataGridView2.DataSource = p_table1;
string data= "update tblStudentInformation set SectionName ='your update value' where Where GradeLevel ='" + label2.Text + "' and Result >= 85 and SectionName IS NULL";
rad = new SqlDataAdapter(data, conn);
rad.Fill(p_table1);
dataGridView2.DataSource = p_table1;
这篇关于如何从datagridview获取数据并将其更新到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文