本文整理汇总了C#中System.Data.DataSet.GetChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.GetChanges方法的具体用法?C# DataSet.GetChanges怎么用?C# DataSet.GetChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataSet
的用法示例。
在下文中一共展示了DataSet.GetChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HaveDataError
/// <summary>
/// Проверяет наличие ошибок в записях
/// </summary>
/// <param name="dataSet">проверяемый DataSet</param>
/// <returns></returns>
internal static bool HaveDataError(DataSet dataSet)
{
DataSet ds = dataSet.GetChanges();
if (ds == null) return false;
if (!ds.HasErrors) return false;
return true;
}
示例2: Main
static void Main(string[] args)
{
const string connectionString =
@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Northwind;Integrated Security=True;";
const string queryString = "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers";
DataSet customersDataSet = new DataSet();
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(queryString, connection);
adapter.Fill(customersDataSet);
SqlCommandBuilder cmdb = new SqlCommandBuilder(adapter);
DataRow row = customersDataSet.Tables[0].NewRow();
row["CustomerID"] = "Dummy";
row["CompanyName"] = "Dummy Company";
row["ContactName"] = "Dummy Contact";
customersDataSet.Tables[0].Rows.Add(row);
DataSet changes = customersDataSet.GetChanges();
if (changes != null)
adapter.Update(changes);
}
Console.ReadKey();
}
示例3: UpdateDataSet
private void UpdateDataSet(DataSet dataSet)
{
if (!dataSet.HasChanges(DataRowState.Modified))
{
return;
}
DataSet tempDataSet = dataSet.GetChanges(DataRowState.Modified);
if (tempDataSet.HasErrors)
{
MessageBox.Show("Data has Errors");
}
else
{
tableAdapterManager.UpdateAll(tempDataSet);
}
}
示例4: Add
public bool Add()
{
DataSet DS = new DataSet();
DataTable DT = new DataTable("Role");
DT.Columns.Add("Role_ID");
DT.Columns.Add("Role_Name");
DS.Tables.Add(DT);
DataRow DR = DS.Tables[0].NewRow();
//
DR["Role_ID"] = this.RoleID;
DR["Role_Name"] = this.Role_Name;
DS.Tables[0].Rows.Add(DR);
//
DataSet DSChange = DS.GetChanges();
return Insert(DSChange);
}
示例5: InsertWithDataSet
public void InsertWithDataSet()
{
var ds = new DataSet();
var da = new NpgsqlDataAdapter("SELECT * FROM data", Conn);
da.InsertCommand = new NpgsqlCommand("INSERT INTO data (field_int2, field_timestamp, field_numeric) VALUES (:a, :b, :c)", Conn);
da.InsertCommand.Parameters.Add(new NpgsqlParameter("a", DbType.Int16));
da.InsertCommand.Parameters.Add(new NpgsqlParameter("b", DbType.DateTime));
da.InsertCommand.Parameters.Add(new NpgsqlParameter("c", DbType.Decimal));
da.InsertCommand.Parameters[0].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[1].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[2].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[0].SourceColumn = "field_int2";
da.InsertCommand.Parameters[1].SourceColumn = "field_timestamp";
da.InsertCommand.Parameters[2].SourceColumn = "field_numeric";
da.Fill(ds);
var dt = ds.Tables[0];
var dr = dt.NewRow();
dr["field_int2"] = 4;
dr["field_timestamp"] = new DateTime(2003, 01, 30, 14, 0, 0);
dr["field_numeric"] = 7.3M;
dt.Rows.Add(dr);
var ds2 = ds.GetChanges();
da.Update(ds2);
ds.Merge(ds2);
ds.AcceptChanges();
var dr2 = new NpgsqlCommand("SELECT field_int2, field_numeric, field_timestamp FROM data", Conn).ExecuteReader();
dr2.Read();
Assert.AreEqual(4, dr2[0]);
Assert.AreEqual(7.3000000M, dr2[1]);
dr2.Close();
}
示例6: DataAdapterUpdateReturnValue
public void DataAdapterUpdateReturnValue()
{
var ds = new DataSet();
var da = new NpgsqlDataAdapter("SELECT * FROM data", Conn);
da.InsertCommand = new NpgsqlCommand(@"INSERT INTO data (field_int2, field_timestamp, field_numeric) VALUES (:a, :b, :c)", Conn);
da.InsertCommand.Parameters.Add(new NpgsqlParameter("a", DbType.Int16));
da.InsertCommand.Parameters.Add(new NpgsqlParameter("b", DbType.DateTime));
da.InsertCommand.Parameters.Add(new NpgsqlParameter("c", DbType.Decimal));
da.InsertCommand.Parameters[0].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[1].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[2].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[0].SourceColumn = "field_int2";
da.InsertCommand.Parameters[1].SourceColumn = "field_timestamp";
da.InsertCommand.Parameters[2].SourceColumn = "field_numeric";
da.Fill(ds);
var dt = ds.Tables[0];
var dr = dt.NewRow();
dr["field_int2"] = 4;
dr["field_timestamp"] = new DateTime(2003, 01, 30, 14, 0, 0);
dr["field_numeric"] = 7.3M;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["field_int2"] = 4;
dr["field_timestamp"] = new DateTime(2003, 01, 30, 14, 0, 0);
dr["field_numeric"] = 7.3M;
dt.Rows.Add(dr);
var ds2 = ds.GetChanges();
var daupdate = da.Update(ds2);
Assert.AreEqual(2, daupdate);
}
示例7: Add
/// <summary>
/// 新增設備資料
/// </summary>
public bool Add()
{
//DataSet DS = new DataSet();
//DataTable DT = new DataTable("Device_Config");
//DT.Columns.Add("Device_ID");
//DT.Columns.Add("DeviceModel");
//DT.Columns.Add("Area_ID");
//DT.Columns.Add("Location");
//DT.Columns.Add("TCModel");
//DT.Columns.Add("DeviceContractID");
//DT.Columns.Add("Status");
//DT.Columns.Add("DeviceNote");
//DT.Columns.Add("Gis_X");
//DT.Columns.Add("Gis_Y");
//DT.Columns.Add("DevicePhoto");
DataSet DS = new DataSet();
DS = Select("1 =0", "", "Device_Config");
//DS.Tables.Add(DT);
DataRow DR = DS.Tables[0].NewRow();
DR["Device_ID"]=this.Device_ID;
DR["DeviceModel"]=this.DeviceModel;
DR["Area_ID"]=this.Area_ID;
DR["Location"]=this.Location;
DR["TCModel"]=this.TCModel;
DR["DeviceContractID"]=this.DeviceContractID;
DR["Status"]=this.Status;
DR["DeviceNote"]=this.DeviceNote;
DR["Gis_X"] = this.Gis_X;
DR["Gis_Y"] = this.Gis_Y;
DR["DevicePhoto"]=this.DevicePhoto;
DS.Tables[0].Rows.Add(DR);
DataSet DSChange=DS.GetChanges();
return Insert(DSChange);
}
示例8: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
DataSet ds = new DataSet();
ds.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());
try
{
BeginCase("GetChanges 1");
Compare(ds.GetChanges(),null );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
DataRow dr = ds.Tables[0].NewRow();
dr[0] = 9;
ds.Tables[0].Rows.Add(dr);
try
{
BeginCase("GetChanges 2");
Compare(ds.GetChanges()!=null,true );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("GetChanges 3");
Compare(ds.GetChanges().Tables[0].Rows[0].ItemArray ,dr.ItemArray);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
示例9: saveData
public bool? saveData(DataSet GridDataSet, DOBangTheoDoi doBangTheoDoi, bool? isAdd)
{
DatabaseFB db = HelpDB.getDatabase();
DbTransaction dbTrans = db.BeginTransaction(db.OpenConnection());
DbCommand cmd = null;
try
{
if (isAdd == true)
insert(cmd, dbTrans, db, doBangTheoDoi);
else
update(cmd, dbTrans, db, doBangTheoDoi);
if (GridDataSet.GetChanges() != null)
db.UpdateDataSet(GridDataSet, dbTrans);
db.CommitTransaction(dbTrans);
}
catch (Exception ex)
{
ex.StackTrace.ToString();
db.RollbackTransaction(dbTrans);
return false;
}
return true;
}
示例10: DoUpdateWithDataSet
public virtual void DoUpdateWithDataSet()
{
var command = new NpgsqlCommand("insert into tableb(field_int2) values (2)", Conn);
command.ExecuteNonQuery();
var ds = new DataSet();
var da = new NpgsqlDataAdapter("select * from tableb where field_serial = (select max(field_serial) from tableb)", Conn);
var cb = new NpgsqlCommandBuilder(da);
Assert.IsNotNull(cb);
da.Fill(ds);
var dt = ds.Tables[0];
Assert.IsNotNull(dt);
var dr = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1];
dr["field_int2"] = 4;
var ds2 = ds.GetChanges();
da.Update(ds2);
ds.Merge(ds2);
ds.AcceptChanges();
using (var dr2 = new NpgsqlCommand("select * from tableb where field_serial = (select max(field_serial) from tableb)", Conn).ExecuteReader())
{
dr2.Read();
Assert.AreEqual(4, dr2["field_int2"]);
}
}
示例11: DoInsertWithCommandBuilderCaseSensitive
public virtual void DoInsertWithCommandBuilderCaseSensitive()
{
var ds = new DataSet();
var da = new NpgsqlDataAdapter("select * from tablei", Conn);
var builder = new NpgsqlCommandBuilder(da);
Assert.IsNotNull(builder);
da.Fill(ds);
var dt = ds.Tables[0];
var dr = dt.NewRow();
dr["Field_Case_Sensitive"] = 4;
dt.Rows.Add(dr);
var ds2 = ds.GetChanges();
da.Update(ds2);
ds.Merge(ds2);
ds.AcceptChanges();
using (var dr2 = new NpgsqlCommand("select * from tablei", Conn).ExecuteReader())
{
dr2.Read();
Assert.AreEqual(4, dr2[1]);
}
}
示例12: btn_MateralAdd_Click
protected void btn_MateralAdd_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
if (Session["MIS_Material"] == null)
{
ds = _operator.Select("1=0", "", "CD_MaterialOfDevice");
}
else
ds = (DataSet)Session["MIS_Material"];
DataRow dr = ds.Tables[0].NewRow();
dr["Device_ID"] = hidden_DeviceID.Value;
dr["Material_NO"] = cbo_MaterialID.SelectedValue;
dr["MaterialName"] = cbo_MaterialID.SelectedItem.Text;
ds.Tables[0].Rows.Add(dr);
////塞流水號
//for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
//{
// ds.Tables[0].Rows[i]["NO"] = i;
//}
DataSet DSChangeAdd = ds.GetChanges(DataRowState.Added);
if (DSChangeAdd != null)
{
if (!_operator.Insert(DSChangeAdd))
{
ShowMsg(UpdatePanel1, "新增失敗");
return;
}
else
{
LoadData();
}
}
}
示例13: UpdateLettingNullFieldValue
public void UpdateLettingNullFieldValue()
{
var command = new NpgsqlCommand(@"INSERT INTO data (field_int2) VALUES (2)", Conn);
command.ExecuteNonQuery();
var ds = new DataSet();
var da = new NpgsqlDataAdapter("SELECT * FROM data", Conn);
da.InsertCommand = new NpgsqlCommand(";", Conn);
da.UpdateCommand = new NpgsqlCommand("UPDATE data SET field_int2 = :a, field_timestamp = :b, field_numeric = :c WHERE field_serial = :d", Conn);
da.UpdateCommand.Parameters.Add(new NpgsqlParameter("a", DbType.Int16));
da.UpdateCommand.Parameters.Add(new NpgsqlParameter("b", DbType.DateTime));
da.UpdateCommand.Parameters.Add(new NpgsqlParameter("c", DbType.Decimal));
da.UpdateCommand.Parameters.Add(new NpgsqlParameter("d", NpgsqlDbType.Bigint));
da.UpdateCommand.Parameters[0].Direction = ParameterDirection.Input;
da.UpdateCommand.Parameters[1].Direction = ParameterDirection.Input;
da.UpdateCommand.Parameters[2].Direction = ParameterDirection.Input;
da.UpdateCommand.Parameters[3].Direction = ParameterDirection.Input;
da.UpdateCommand.Parameters[0].SourceColumn = "field_int2";
da.UpdateCommand.Parameters[1].SourceColumn = "field_timestamp";
da.UpdateCommand.Parameters[2].SourceColumn = "field_numeric";
da.UpdateCommand.Parameters[3].SourceColumn = "field_serial";
da.Fill(ds);
var dt = ds.Tables[0];
Assert.IsNotNull(dt);
var dr = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1];
dr["field_int2"] = 4;
var ds2 = ds.GetChanges();
da.Update(ds2);
ds.Merge(ds2);
ds.AcceptChanges();
using (var dr2 = new NpgsqlCommand(@"SELECT field_int2 FROM data", Conn).ExecuteReader())
{
dr2.Read();
Assert.AreEqual(4, dr2["field_int2"]);
}
}
示例14: ExecuteIndexerOnDataStore
/// <summary>
/// Indexes a MyLo datastore using PostgreSQL function 'SetupIndexCursorsIntervalAndTimePoints'
/// </summary>
public int ExecuteIndexerOnDataStore()
{
try
{
DataSet indexDS = new DataSet();
NpgsqlTransaction t = _conn.BeginTransaction();
NpgsqlCommand command = new NpgsqlCommand("SetupIndexCursorsOrdered", _conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new NpgsqlParameter());
command.Parameters[0].DbType = DbType.Int64;
command.Parameters[0].Value = _userId;
NpgsqlCommand updateCommandforPhotos = new NpgsqlCommand("UpdatePhotoActivityId", _conn);
updateCommandforPhotos.CommandType = CommandType.StoredProcedure;
updateCommandforPhotos.Parameters.Add(new NpgsqlParameter());
updateCommandforPhotos.Parameters.Add(new NpgsqlParameter());
updateCommandforPhotos.Parameters.Add(new NpgsqlParameter());
updateCommandforPhotos.Parameters[0].DbType = DbType.Int64;
updateCommandforPhotos.Parameters[1].DbType = DbType.Guid;
updateCommandforPhotos.Parameters[2].DbType = DbType.Int64;
updateCommandforPhotos.Parameters[0].Value = _userId;
updateCommandforPhotos.Parameters[1].SourceColumn = "uniqueid";
updateCommandforPhotos.Parameters[2].SourceColumn = "activityid";
NpgsqlDataAdapter postgresqlAdapterForPhotos = new NpgsqlDataAdapter(command);
postgresqlAdapterForPhotos.UpdateCommand = updateCommandforPhotos;
NpgsqlCommand commandForActivities = new NpgsqlCommand("SetupIndexCursorsIntervalAndTimePoints", _conn);
commandForActivities.CommandType = CommandType.StoredProcedure;
commandForActivities.Parameters.Add(new NpgsqlParameter());
commandForActivities.Parameters.Add(new NpgsqlParameter());
commandForActivities.Parameters.Add(new NpgsqlParameter());
commandForActivities.Parameters[0].DbType = DbType.Int64;
commandForActivities.Parameters[1].DbType = DbType.DateTime;
commandForActivities.Parameters[2].DbType = DbType.Int32;
commandForActivities.Parameters[0].Value = _userId;
NpgsqlDataAdapter postgresqlAdapterForActivities = new NpgsqlDataAdapter(commandForActivities);
postgresqlAdapterForPhotos.Fill(indexDS);
DataTable photos = indexDS.Tables[0];
_countIndexed = 0;
foreach (DataRow photo in photos.Rows)
{
DataSet activitiesDS = new DataSet();
// TODO - remove the Fill when datetaken time is still within the last retrieved activity interval
commandForActivities.Parameters[1].Value = photo["datetaken"];
// TODO - make this hours radius a variable set in UI
commandForActivities.Parameters[2].Value = 4;
postgresqlAdapterForActivities.Fill(activitiesDS);
DataTable activities = activitiesDS.Tables[0];
// TODO - the function returns the data sorted by duration, but this order is not preserved by ADO.Net!! Need to investigate
// and avoid the use of the ADO.Net sorted view.
DataView activitiesView = activities.DefaultView;
activitiesView.Sort = "duration ASC";
DataTable activitiesSorted = activitiesView.ToTable();
//foreach (DataRow activity in activities.Rows)
foreach (DataRow activity in activitiesSorted.Rows)
{
if ((Double)photo["gpsLat"] != 0.0)
{
if (IsSameLocation(photo, activity, 2.0))
{
photo["activityid"] = activity["activityid"];
Debug.WriteLine("Indexed Photoid Location and Time: {0} to ActivityId: {1}", photo["uniqueid"], activity["activityid"]);
Debug.WriteLine("Photo time: {0} Activity time: {1} ", photo["datetaken"], activity["startdatetime"]);
Debug.WriteLine("Photo loc: {0}, {1} Activity loc: {2}, {3} ", photo["gpslat"], photo["gpslong"], activity["latitude"], activity["longitude"]);
Debug.WriteLine("");
_countIndexed++;
break;
}
}
else
{
photo["activityid"] = activity["activityid"];
_countIndexed++;
Debug.WriteLine("Indexed Photoid Time only: {0} to ActivityId: {1}", photo["uniqueid"], activity["activityid"]);
Debug.WriteLine("Photo time: {0} Activity time: {1} ", photo["datetaken"], activity["startdatetime"]);
Debug.WriteLine("");
break;
}
}
}
t.Commit();
// now write changes back to the database
DataSet changeDS = indexDS.GetChanges(DataRowState.Modified);
if (changeDS != null)
{
postgresqlAdapterForPhotos.Update(changeDS);
indexDS.Merge(changeDS);
indexDS.AcceptChanges();
//.........这里部分代码省略.........
示例15: cmd_Save_Click1
protected void cmd_Save_Click1(object sender, EventArgs e)
{
SQLDB deviceModel = new SQLDB("DeviceKind");
if (hidden_Action.Value.Equals("add")) {
DataSet DS = new DataSet();
DataTable DT = new DataTable("DeviceKind");
DT.Columns.Add("DeviceKindId");
DT.Columns.Add("DeviceKind");
DT.Columns.Add("DeviceKindName");
DS.Tables.Add(DT);
DataRow DR = DS.Tables[0].NewRow();
DR["DeviceKindId"] = deviceModel.Select().Tables[0].Rows.Count + 1;
DR["DeviceKind"] = txt_equipmentKind.Text;
DR["DeviceKindName"] = txt_DeviceKindName.Text;
DS.Tables[0].Rows.Add(DR);
DataSet _changed = DS.GetChanges();
if (deviceModel.Insert(_changed))
{
ReDirect("新增成功");
}
else {
ReDirect("新增失敗");
}
}
else if (hidden_Action.Value.Equals("edit")){
DataSet ds = (DataSet)Session["DS_Mis"];
if (ds != null){
ds.Tables[0].Rows[0]["DeviceKind"] = txt_equipmentKind.Text;
ds.Tables[0].Rows[0]["DeviceKindName"] = txt_DeviceKindName.Text;
DataSet DSChange = ds.GetChanges(DataRowState.Modified);
if (deviceModel.Update(DSChange))
{
ReDirect("修改成功");
}
else {
ReDirect("修改失敗");
}
}
}
}