SqlDataAdapter和SqlCommandBuilder删除数据
生活随笔
收集整理的這篇文章主要介紹了
SqlDataAdapter和SqlCommandBuilder删除数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
using System;
using System.Data;
using System.Data.SqlClient;//SqlDataAdapter網站:http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx
//SqlCommandBuilder網站:http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspxnamespace Chapter13
{class PersistDels{static void Main(string[] args){// connection stringstring connString = @"server = .;integrated security = true;database = northwind";// querystring qry = @"select*fromemployeeswherecountry = 'UK'";// Create connectionSqlConnection conn = new SqlConnection(connString);try{// create data adapterSqlDataAdapter da = new SqlDataAdapter();da.SelectCommand = new SqlCommand(qry, conn);SqlCommandBuilder sqlCmdBder = new SqlCommandBuilder(da);// create and fill datasetDataSet ds = new DataSet();da.Fill(ds, "employees");// get data table referenceDataTable dt = ds.Tables["employees"];// display rowsforeach (DataRow row in dt.Rows){Console.WriteLine("{0} {1} {2}",row["firstname"].ToString().PadRight(15),row["lastname"].ToString().PadLeft(25),row["city"]);}string filt = @"firstname = 'Roy'andlastname = 'Beatty'";//// delete employeesforeach (DataRow row in dt.Select(filt)){row.Delete();}//很重要的一步,把本地修改提交至至數據庫。da.Update(ds, "employees");}catch (Exception e){Console.WriteLine("Error: " + e);}finally{// close connectionconn.Close();}}}
}
轉載于:https://www.cnblogs.com/java20130722/archive/2012/03/07/3207186.html
總結
以上是生活随笔為你收集整理的SqlDataAdapter和SqlCommandBuilder删除数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转载]ZIGBEE:Coordinat
- 下一篇: RDLC报表系列--------钻取报表