通过DataSet删除表中所有记录
写了一段代码。VS2005下C#语言。代码目的就是查看当前的表中,是否表中已经有记录,如果有,则清空该表,以备写入数据。可是我用下面这样一段代码清空DataSet中数据,然后用Update将修改映射回原表实,发现DataSet中的数据被删除了,可是表中数据还没有删除。这是从一个教程中看得代码,难道写的有问题吗?发现用了这个DataSet只能对表中数据写入,不能更新和删除记录,这是怎么回事啊?请大牛多多帮助,谢谢!
附代码:
thisConnection = new SqlConnection("Data Source=(local);Database=ShortMessageHotSpot;Persist Security Info=True;User ID=sa; pwd=;");
thisAdaper = new SqlDataAdapter("SELECT * From " + table, thisConnection);
thisCommandBuilder = new SqlCommandBuilder(thisAdaper);
thisDataSet = new DataSet();
thisAdaper.Fill(thisDataSet, table);
tableName = table;
if (thisDataSet.Tables[tableName].Rows.Count != 0)
{
Console.WriteLine("\n Great Change :"+thisDataSet.Tables[tableName].Rows.Count);
thisDataSet.Tables[tableName].Rows.Clear();
// thisDataSet.Tables[tableName].Clear();
Console.WriteLine("\n Great Change Take Place :" + thisDataSet.Tables[tableName].Rows.Count);
thisAdaper.Update(thisDataSet, tableName);
}
附代码:
thisConnection = new SqlConnection("Data Source=(local);Database=ShortMessageHotSpot;Persist Security Info=True;User ID=sa; pwd=;");
thisAdaper = new SqlDataAdapter("SELECT * From " + table, thisConnection);
thisCommandBuilder = new SqlCommandBuilder(thisAdaper);
thisDataSet = new DataSet();
thisAdaper.Fill(thisDataSet, table);
tableName = table;
if (thisDataSet.Tables[tableName].Rows.Count != 0)
{
Console.WriteLine("\n Great Change :"+thisDataSet.Tables[tableName].Rows.Count);
thisDataSet.Tables[tableName].Rows.Clear();
// thisDataSet.Tables[tableName].Clear();
Console.WriteLine("\n Great Change Take Place :" + thisDataSet.Tables[tableName].Rows.Count);
thisAdaper.Update(thisDataSet, tableName);
}
...全文
相关推荐
asp.net使用DataSet数据集插入表记录
asp.net使用DataSet数据集插入表记录
Metis异常检测样本管理源码分析
Metis异常检测样本管理源码分析
操作无连接数据库dataset
无连接的操作,对于速度有所提升,和服务器交换数据
C#中DataSet的用法(很详细)
DataSet是ADO.NET开发人员为方便数据处理开发出来的,是数据的集合。DataSet的功能:浏览、排序、搜索、过滤、处理分级数据、缓存更改等。还可以与XML数据互换。DataSet中可包括多个DataTable,可将多个查询结构存到一个DataSet中,方便操作.....
C#中数据库的更新和删除记录的两种实现方式.pdf
C#中数据库的更新和删除记录的两种实现方式.pdf


