`Adapter.Update (DataTable);` 方法更新 table 数据源的所有行,还是仅更新那些已修改的行?
The `Adapter.Update (DataTable);` method updates all rows of the table data source or only those rows that have been modified?
Adapter.Update (DataTable);
方法更新 table 数据源的所有行,还是仅更新那些已修改的行?
逻辑:
- 连接到数据库;
- 我们对 tables;
行进行抽样
- 用户进行更改;
- 保存。方法Save()
。
我使用代码来处理数据库:
public DataTable CreateCmds()
{
table_2 = new DataTable();
try
{
string connectionString = @"Data Source=.\SQLEXPRESS1;Initial Catalog=Prb;Integrated Security=True";
string queryString = "SELECT * FROM tbl_01_Groups";
// string connectString = "Data Source=.\SQLEXPRESS;Initial Catalog=LSTU_Schedule_autumn20172018;" + "Integrated Security=true;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(queryString, connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
connection.Open();
adapter.Fill(table_2);
}
}
catch (Exception ex)
{
string s = ex.Message;
string t = ex.StackTrace;
// throw;
}
return table_2;
}
public void Save()
{
string connectionString = @"Data Source=.\SQLEXPRESS1;Initial Catalog=Prb;Integrated Security=True";
string queryString = "SELECT * FROM tbl_01_Groups";
using (SqlConnection connection = new SqlConnection(connectionString))
{
adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(queryString, connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
connection.Open();
adapter.Update(table_2);
}
}
Update_1
我在网络上没有找到答案,这个问题的解决方法。
问题是代码效率提升引起的
我以为执行表达式adapter.Update(DataTable)
时,代码会遍历数据源table.
的所有行
如果是这种情况,那么可能有更有效的方法来对代码进行采样以仅更新更改的行。
DataTable.Rows[index].RowState 指的是数据行的状态。
ADO.NET 将检查状态,仅在状态更改时更新。
The update is performed on a by-row basis. For every inserted, modified, and deleted row, the Update method determines the type of change that has been performed on it
Adapter.Update (DataTable);
方法更新 table 数据源的所有行,还是仅更新那些已修改的行?
逻辑:
- 连接到数据库;
- 我们对 tables;
行进行抽样
- 用户进行更改;
- 保存。方法Save()
。
我使用代码来处理数据库:
public DataTable CreateCmds()
{
table_2 = new DataTable();
try
{
string connectionString = @"Data Source=.\SQLEXPRESS1;Initial Catalog=Prb;Integrated Security=True";
string queryString = "SELECT * FROM tbl_01_Groups";
// string connectString = "Data Source=.\SQLEXPRESS;Initial Catalog=LSTU_Schedule_autumn20172018;" + "Integrated Security=true;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(queryString, connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
connection.Open();
adapter.Fill(table_2);
}
}
catch (Exception ex)
{
string s = ex.Message;
string t = ex.StackTrace;
// throw;
}
return table_2;
}
public void Save()
{
string connectionString = @"Data Source=.\SQLEXPRESS1;Initial Catalog=Prb;Integrated Security=True";
string queryString = "SELECT * FROM tbl_01_Groups";
using (SqlConnection connection = new SqlConnection(connectionString))
{
adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(queryString, connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
connection.Open();
adapter.Update(table_2);
}
}
Update_1
我在网络上没有找到答案,这个问题的解决方法。
问题是代码效率提升引起的
我以为执行表达式adapter.Update(DataTable)
时,代码会遍历数据源table.
的所有行
如果是这种情况,那么可能有更有效的方法来对代码进行采样以仅更新更改的行。
DataTable.Rows[index].RowState 指的是数据行的状态。
ADO.NET 将检查状态,仅在状态更改时更新。
The update is performed on a by-row basis. For every inserted, modified, and deleted row, the Update method determines the type of change that has been performed on it