/// <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; }
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(); }
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); } }
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); }
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(); }
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); }
/// <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); }
//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;} }
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; }
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"]); } }
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]); } }
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(); } } }
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"]); } }
/// <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(); } _conn.Close(); return _countIndexed; } catch (System.Data.DBConcurrencyException daex) { _conn.Close(); Debug.WriteLine("Exception Data {0}", daex.Data); throw new MyLoDataStoreException(daex.Message, daex); } catch (NpgsqlException npex) { _conn.Close(); throw new MyLoDataStoreException(npex.Message, npex); } catch (Exception ex) { _conn.Close(); throw new MyLoDataStoreException(ex.Message); } }
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("修改失敗"); } } } }
[Test] public void GetChanges_ByDataRowState() { DataSet ds = new DataSet(); object[] arrAdded,arrDeleted,arrModified,arrUnchanged; //object[] arrDetached; DataRow dr; ds.Tables.Add(DataProvider.CreateParentDataTable()); // GetChanges 1 Assert.AreEqual(null , ds.GetChanges(), "DS29"); //make some changes // can't check detached // dr = ds.Tables[0].Rows[0]; // arrDetached = dr.ItemArray; // dr.Delete(); // ds.Tables[0].AcceptChanges(); dr= ds.Tables[0].Rows[1]; arrDeleted = dr.ItemArray; dr.Delete(); dr = ds.Tables[0].Rows[2]; dr[1] = "NewValue"; arrModified = dr.ItemArray; dr = ds.Tables[0].Select("","",DataViewRowState.Unchanged)[0]; arrUnchanged = dr.ItemArray; dr = ds.Tables[0].NewRow(); dr[0] = 1; ds.Tables[0].Rows.Add(dr); arrAdded = dr.ItemArray; // GetChanges Added Assert.AreEqual(arrAdded, ds.GetChanges(DataRowState.Added).Tables[0].Rows[0].ItemArray , "DS30"); // GetChanges Deleted dr = ds.GetChanges(DataRowState.Deleted).Tables[0].Rows[0]; object[] tmp = new object[] {dr[0,DataRowVersion.Original],dr[1,DataRowVersion.Original],dr[2,DataRowVersion.Original],dr[3,DataRowVersion.Original],dr[4,DataRowVersion.Original],dr[5,DataRowVersion.Original]}; Assert.AreEqual(arrDeleted, tmp, "DS31"); // can't check it // // GetChanges Detached // dr = ds.GetChanges(DataRowState.Detached).Tables[0].Rows[0]; // object[] tmp = new object[] {dr[0,DataRowVersion.Original],dr[1,DataRowVersion.Original],dr[2,DataRowVersion.Original]}; // Assert.AreEqual(arrDetached, tmp, "DS32"); // GetChanges Modified Assert.AreEqual(arrModified, ds.GetChanges(DataRowState.Modified).Tables[0].Rows[0].ItemArray , "DS33"); // GetChanges Unchanged Assert.AreEqual(arrUnchanged, ds.GetChanges(DataRowState.Unchanged).Tables[0].Rows[0].ItemArray , "DS34"); }
public void DifferentDatabase() { if (Version < new Version(4, 1)) return; execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(100), dt DATETIME, tm TIME, `multi word` int, PRIMARY KEY(id))"); execSQL("INSERT INTO Test (id, name) VALUES (1,'test1')"); execSQL("INSERT INTO Test (id, name) VALUES (2,'test2')"); execSQL("INSERT INTO Test (id, name) VALUES (3,'test3')"); conn.ChangeDatabase(database1); MySqlDataAdapter da = new MySqlDataAdapter( String.Format("SELECT id, name FROM `{0}`.Test", database0), conn); MySqlCommandBuilder cb = new MySqlCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); ds.Tables[0].Rows[0]["id"] = 4; DataSet changes = ds.GetChanges(); da.Update(changes); ds.Merge(changes); ds.AcceptChanges(); cb.Dispose(); conn.ChangeDatabase(database0); }
[Category ("NotWorking")] // Requires newer sqlite than is on wrench public void UpdateResetRowErrorCorrectly () { const string connectionString = "URI = file::memory:; Version = 3"; using (var dbConnection = new SqliteConnection (connectionString)) { dbConnection.Open (); using (var cmd = dbConnection.CreateCommand ()) { cmd.CommandText = "CREATE TABLE data (id PRIMARY KEY, name TEXT)"; cmd.ExecuteNonQuery (); } var ts = dbConnection.BeginTransaction (); var da = new SqliteDataAdapter ("SELECT * FROM data", dbConnection); var builder = new SqliteCommandBuilder (da); da.UpdateCommand = builder.GetUpdateCommand (); da.UpdateCommand.Transaction = ts; var ds1 = new DataSet (); da.Fill (ds1, "data"); var table = ds1.Tables [0]; var row = table.NewRow (); row ["id"] = 10; row ["name"] = "Bart"; table.Rows.Add (row); var ds2 = ds1.GetChanges (); da.Update (ds2, "data"); Assert.IsFalse (ds2.HasErrors); } }
public void InsertWithDataSet() { _conn.Open(); DataSet ds = new DataSet(); NpgsqlDataAdapter da = new NpgsqlDataAdapter("select * from tableb", _conn); da.InsertCommand = new NpgsqlCommand("insert into tableb(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); DataTable dt = ds.Tables[0]; DataRow dr = dt.NewRow(); dr["field_int2"] = 4; dr["field_timestamp"] = new DateTime(2003, 03, 03, 14, 0, 0); dr["field_numeric"] = 7.3M; dt.Rows.Add(dr); DataSet ds2 = ds.GetChanges(); da.Update(ds2); ds.Merge(ds2); ds.AcceptChanges(); NpgsqlDataReader dr2 = new NpgsqlCommand("select * from tableb where field_serial > 4", _conn).ExecuteReader(); dr2.Read(); Assert.AreEqual(4, dr2[1]); Assert.AreEqual(7.3000000M, dr2[3]); new NpgsqlCommand("delete from tableb where field_serial > 4", _conn).ExecuteNonQuery(); }
/// <summary> /// Indexes a MyLo datastore using PostgreSQL function 'SetUpIndexCursorsPhotosAndActivities' /// </summary> public int ExecuteIndexerOnDataStore() { try { DataSet indexDS = new DataSet(); NpgsqlTransaction t = _conn.BeginTransaction(); NpgsqlCommand command = new NpgsqlCommand("SetUpIndexCursorsPhotosAndActivities", _conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new NpgsqlParameter()); command.Parameters[0].DbType = DbType.Int64; command.Parameters[0].Value = _userId; NpgsqlCommand updateCommand = new NpgsqlCommand("UpdatePhotoActivityId", _conn); updateCommand.CommandType = CommandType.StoredProcedure; updateCommand.Parameters.Add(new NpgsqlParameter()); updateCommand.Parameters.Add(new NpgsqlParameter()); updateCommand.Parameters.Add(new NpgsqlParameter()); updateCommand.Parameters[0].DbType = DbType.Int64; updateCommand.Parameters[1].DbType = DbType.Guid; updateCommand.Parameters[2].DbType = DbType.Int64; updateCommand.Parameters[0].Value = _userId; updateCommand.Parameters[1].SourceColumn = "uniqueid"; updateCommand.Parameters[2].SourceColumn = "activityid"; NpgsqlDataAdapter postgresqlAdapter = new NpgsqlDataAdapter(command); postgresqlAdapter.UpdateCommand = updateCommand; postgresqlAdapter.Fill(indexDS); DataTable photos = indexDS.Tables[0]; DataTable activities = indexDS.Tables[1]; _countIndexed = 0; foreach (DataRow photo in photos.Rows) { foreach (DataRow activity in activities.Rows) { if ((Double)photo["gpsLat"] != 0.0) { // We have GPS coordinates for the photo if (IsSameTime(photo, activity, 4) && IsSameLocation(photo, activity, 1.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 { // We do NOT have GPS coordinates for the photo if (IsSameTime(photo, activity, 4)) { 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) { postgresqlAdapter.Update(changeDS); indexDS.Merge(changeDS); indexDS.AcceptChanges(); } _conn.Close(); return _countIndexed; } catch (System.Data.DBConcurrencyException daex) { _conn.Close(); Debug.WriteLine("Exception Data {0}", daex.Data); throw new MyLoDataStoreException(daex.Message, daex); } catch (NpgsqlException npex) { _conn.Close(); throw new MyLoDataStoreException(npex.Message, npex); } catch (Exception ex) { _conn.Close(); throw new MyLoDataStoreException(ex.Message); } }
public static void GrabarDB(DataSet dt, DataTable tblFallidas ,ref int? codigoError, bool grabarFallidas) { try { if (grabarFallidas == false) { DataSet dsRemoto; dsRemoto = dt.GetChanges(); DAL.ClientesDAL.GrabarDB(dt, grabarFallidas); lock (_sync) { Thread t = new Thread(() => ThreadSaveEnRemoteServer(dsRemoto, tblFallidas)); t.Start(); } } else { DAL.ClientesDAL.GrabarDB(dt, grabarFallidas); } } catch (MySqlException ex) { if (ex.Number == 1042) //no se pudo abrir la conexion por falta de internet { dt.RejectChanges(); ; codigoError = 1042; } else { dt.RejectChanges(); codigoError = ex.Number; } } }
public void DataAdapterUpdateReturnValue() { DataSet ds = new DataSet(); NpgsqlDataAdapter da = new NpgsqlDataAdapter("select * from tableb", TheConnection); da.InsertCommand = new NpgsqlCommand("insert into tableb(field_int2, field_timestamp, field_numeric) values (:a, :b, :c)", TheConnection); 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); DataTable dt = ds.Tables[0]; DataRow 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); DataSet ds2 = ds.GetChanges(); int daupdate = da.Update(ds2); Assert.AreEqual(2, daupdate); }
[Test] public void GetChanges() { DataSet ds = new DataSet(); ds.Tables.Add(DataProvider.CreateParentDataTable()); // GetChanges 1 Assert.AreEqual(null , ds.GetChanges(), "DS26"); DataRow dr = ds.Tables[0].NewRow(); dr[0] = 9; ds.Tables[0].Rows.Add(dr); // GetChanges 2 Assert.AreEqual(true , ds.GetChanges()!=null, "DS27"); // GetChanges 3 Assert.AreEqual(dr.ItemArray, ds.GetChanges().Tables[0].Rows[0].ItemArray , "DS28"); }
/// <summary> /// Saves the specified DataSet /// </summary> /// <param name="ds">The DataSet to save</param> /// <param name="conn">The open IDbConnection to use</param> /// <returns>Number of modified records</returns> public virtual int SaveDS(DataSet ds, IDbConnection conn) { DbDataAdapter da = DbProviderFactory.CreateDataAdapter(this.Provider, this.CreateSelectAllCommand(), conn); int modified = 0; DataSet modifiedDS = ds.GetChanges(); if (modifiedDS != null) { if (this.Provider == DbProviderType.SQLSERVER) { SqlCommandBuilder cb = new SqlCommandBuilder((SqlDataAdapter) da); foreach (DataTable dt in modifiedDS.Tables) { modified += da.Update(modifiedDS, dt.TableName); } } else { OleDbCommandBuilder cb = new OleDbCommandBuilder((OleDbDataAdapter) da); foreach (DataTable dt in modifiedDS.Tables) { modified += da.Update(modifiedDS, dt.TableName); } } return modified; } else { return 0; } }
// Sauvegarde tous les changements effectué dans le dataset public void SaveDataSet(string tableName, DataSet dataSet) { if (dataSet.HasChanges() == false) return; switch (connType) { case ConnectionType.DATABASE_MSSQL: { try { var conn = new SqlConnection(connString); var adapter = new SqlDataAdapter("SELECT * from " + tableName, conn); var builder = new SqlCommandBuilder(adapter); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand = builder.GetInsertCommand(); lock (dataSet) // lock dataset to prevent changes to it { adapter.ContinueUpdateOnError = true; DataSet changes = dataSet.GetChanges(); adapter.Update(changes, tableName); PrintDatasetErrors(changes); dataSet.AcceptChanges(); } conn.Close(); } catch (Exception ex) { throw new DatabaseException("Can not save table " + tableName, ex); } break; } case ConnectionType.DATABASE_ODBC: { try { var conn = new OdbcConnection(connString); var adapter = new OdbcDataAdapter("SELECT * from " + tableName, conn); var builder = new OdbcCommandBuilder(adapter); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand = builder.GetInsertCommand(); DataSet changes; lock (dataSet) // lock dataset to prevent changes to it { adapter.ContinueUpdateOnError = true; changes = dataSet.GetChanges(); adapter.Update(changes, tableName); dataSet.AcceptChanges(); } PrintDatasetErrors(changes); conn.Close(); } catch (Exception ex) { throw new DatabaseException("Can not save table ", ex); } break; } case ConnectionType.DATABASE_MYSQL: { return; } case ConnectionType.DATABASE_OLEDB: { try { var conn = new OleDbConnection(connString); var adapter = new OleDbDataAdapter("SELECT * from " + tableName, conn); var builder = new OleDbCommandBuilder(adapter); adapter.DeleteCommand = builder.GetDeleteCommand(); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand = builder.GetInsertCommand(); DataSet changes; lock (dataSet) // lock dataset to prevent changes to it { adapter.ContinueUpdateOnError = true; changes = dataSet.GetChanges(); adapter.Update(changes, tableName); dataSet.AcceptChanges(); } PrintDatasetErrors(changes); conn.Close(); } catch (Exception ex) { throw new DatabaseException("Can not save table", ex); } break; } } }
protected void cmd_Save_Click1(object sender, EventArgs e) { if (txt_contractNum.Text.Length == 0) { ShowPageMsg("請輸入合約編號"); return; } if (txt_contractName.Text.Length == 0) { ShowPageMsg("請輸入合約名稱"); return; } if (txt_contractShortName.Text.Length == 0) { ShowPageMsg("請輸入合約簡稱"); return; } if (ddl_company.SelectedValue == "0") { ShowPageMsg("請選擇得標廠商"); return; } if (txt_contractStartDate.Text.Length == 0) { ShowPageMsg("請選擇保固起始日"); return; } if (txt_contractEndDate.Text.Length == 0) { ShowPageMsg("請選擇保固中止日"); return; } DateTime start = Convert.ToDateTime(txt_contractStartDate.Text); DateTime end = Convert.ToDateTime(txt_contractEndDate.Text); if (DateTime.Compare( end, start) == -1) { ShowPageMsg("請選擇保固中止日不得小於保固起始日"); return; } if (hidden_Action.Value.Equals("add")) { DataSet DS = new DataSet(); DataTable DT = new DataTable("Contract"); DT.Columns.Add("ContractId"); DT.Columns.Add("ContractNum"); DT.Columns.Add("ContractName"); DT.Columns.Add("ContractShortName"); DT.Columns.Add("SubContractName"); DT.Columns.Add("Company"); DT.Columns.Add("ContractStartDate"); DT.Columns.Add("ContractEndDate"); DT.Columns.Add("Note"); DT.Columns.Add("Display"); DS.Tables.Add(DT); DataRow DR = DS.Tables[0].NewRow(); //DR["ContractId"] = contract.Select().Tables[0].Rows.Count + 1; DR["ContractNum"] = txt_contractNum.Text; DR["ContractName"] = txt_contractName.Text; DR["ContractShortName"] = txt_contractShortName.Text; DR["SubContractName"] = txt_subContractName.Text; DR["Company"] = ddl_company.SelectedValue.ToString(); if (txt_contractStartDate.Text.Length > 0) DR["ContractStartDate"] = txt_contractStartDate.Text; else DR["ContractStartDate"] = "NULL"; if (txt_contractEndDate.Text.Length > 0) DR["ContractEndDate"] = txt_contractEndDate.Text; else DR["ContractEndDate"] = "NULL"; DR["Note"] = txt_note.Text; //DR["Display"] = ddl_display.SelectedValue; DS.Tables[0].Rows.Add(DR); DataSet _changed = DS.GetChanges(); if (contract.Insert(_changed)) { ReDirect("新增成功"); UpdateServerData(); } else { ReDirect("新增失敗"); } } else if (hidden_Action.Value.Equals("edit")) { DataSet ds = (DataSet)Session["DS_Mis"]; if (ds != null) { //ds.Tables[0].Rows[0]["ContractId"] = txt_contractId.Text; ds.Tables[0].Rows[0]["ContractNum"] = txt_contractNum.Text; ds.Tables[0].Rows[0]["ContractName"] = txt_contractName.Text; ds.Tables[0].Rows[0]["ContractShortName"] = txt_contractShortName.Text; ds.Tables[0].Rows[0]["SubContractName"] = txt_subContractName.Text; ds.Tables[0].Rows[0]["Company"] = ddl_company.SelectedValue.ToString(); if(txt_contractStartDate.Text.Length > 0) ds.Tables[0].Rows[0]["ContractStartDate"] = txt_contractStartDate.Text; if(txt_contractEndDate.Text.Length > 0) ds.Tables[0].Rows[0]["ContractEndDate"] = txt_contractEndDate.Text; ds.Tables[0].Rows[0]["Note"] = txt_note.Text; //ds.Tables[0].Rows[0]["Display"] = ddl_display.SelectedValue; if (contract.Update(ds)) { ReDirect("修改成功"); UpdateServerData(); } else { ReDirect("修改失敗"); } } } }
protected void Button1_Click(object sender, EventArgs e) { Staff _operator = new Staff("Company"); //物料名稱 String my_MaterialName = txt_MaterialName.Text; //物料單位 String my_MaterialUnit = txt_MaterialUnit.Text; //安全存量 String my_MaterialSafeQuantity = txt_MaterialSafeQuantity.Text; //更新人員 String USER; if (Session["UserID"] != null) { USER = Session["UserID"].ToString(); } else { USER = "******"; } if (hidden_Action.Value == "add") { string sql = "INSERT INTO ICS_Material (MaterialName,MaterialUnit,MaterialSafeQuantity,UpdateTime,UpdateUser,MaterialTypeID) VALUES ('" + my_MaterialName.ToString() + "','" + my_MaterialUnit.ToString() + "','" + my_MaterialSafeQuantity.ToString() + "',getdate(),'" + USER + "','" + cbo_materialType.SelectedValue + "') "; if (_operator.ExecuteStatement(sql)) { ShowMsg2(UpdatePanel1, "儲存成功"); UpdateServerData(); //更新Application Data Response.AddHeader("Refresh", "3; url=Inventory_AQM.aspx"); } else { ShowMsg2(UpdatePanel1, "儲存失敗"); } } else { SQLDB db = new SQLDB(); DataSet ds = new DataSet(); ds = db.Select("NO = '"+hidden_Materialid.Value+"'","","ICS_Material"); DataRow dr = ds.Tables[0].Rows[0]; dr["MaterialName"] = my_MaterialName.ToString(); dr["MaterialUnit"] = my_MaterialUnit.ToString(); dr["MaterialSafeQuantity"] = my_MaterialSafeQuantity.ToString(); dr["UpdateTime"] = DateTime.Now; dr["UpdateUser"] = USER; dr["MaterialTypeID"] = cbo_materialType.SelectedValue; DataSet DSChange = ds.GetChanges(DataRowState.Modified); //string sql = "UPDATE from ICS_Material (MaterialName,MaterialUnit,MaterialSafeQuantity,UpdateTime,UpdateUser,MaterialTypeID) VALUES ('" + my_MaterialName.ToString() + "','" + my_MaterialUnit.ToString() + "','" + my_MaterialSafeQuantity.ToString() + "',getdate(),'" + USER + "','" + cbo_materialType.SelectedValue + "') "; if (db.Update(DSChange)) { ShowMsg2(UpdatePanel1, "儲存成功"); UpdateServerData(); //更新Application Data Response.AddHeader("Refresh", "3; url=Inventory_AQM.aspx"); } else { ShowMsg2(UpdatePanel1, "儲存失敗"); } } }
protected void OnBeforeApplyUpdates(EventArgs value) { EventHandler handler = (EventHandler)base.Events[EventOnBeforeApplyUpdates]; if (handler != null) { handler(this, value); } DataTable mergeTab = new DataTable(); DataSet mergedataset = new DataSet(); DataSet ds = new DataSet(); if (this.Container != null) { int i = this.Container.Components.Count; for (int j = 0; j < i; j++) { if (this.Container.Components[j] is InfoBindingSource) { InfoBindingSource bs = (InfoBindingSource)this.Container.Components[j]; int m = bs.Relations.Count; for (int n = 0; n < m; n++) { InfoRelation infoRel = bs.Relations[n]; ds = this.fRealDataSet; if (infoRel.RelationDataSet.GetRealDataSet() == ds) { if (ds.HasChanges()) { string strTabName = this.RemoteName.Substring(this.RemoteName.IndexOf('.') + 1); mergeTab = ds.GetChanges().Tables[strTabName]; mergedataset = ds.GetChanges(); if (((InfoDataSet)bs.GetDataSource()).RealDataSet.Tables[0].Rows.Count == 0) { bs.Set_fEmptyViewMerge(); } //2008/8/4 by ccm, 解决最后一笔无法删除的问题,取消DoDelay事件,避免触发使master重新取资料变为unchanged,导致无法删除。 bs.CancelPositionChanged = true; ((InfoDataSet)bs.GetDataSource()).RealDataSet.Tables[0].Merge(mergeTab); bs.CancelPositionChanged = false; //2008-9-9 Modified by lily 最後一筆master無法删除的問題。View在merge后master的資料會不見,重新merge一次master。 if (mergeTab.Rows.Count > 0 && mergeTab.Rows[0].RowState == DataRowState.Deleted) { //2007/01/12 Master-Detail-View因为无法删除最后一笔资料而新增 by Rax ds.Tables[strTabName].Merge(mergeTab); foreach (DataTable tb in ds.Tables) { if (mergedataset.Tables[tb.TableName] != null) { tb.Merge(mergedataset.Tables[tb.TableName]); } } //2007/01/12 end } ArrayList keyFields = this.GetKeyFields(); int p = mergeTab.Rows.Count - 1; if (p >= 0 && (mergeTab.Rows[p].RowState == DataRowState.Added || mergeTab.Rows[p].RowState == DataRowState.Modified)) { int x = keyFields.Count; object[] keyValues = new object[x]; for (int y = 0; y < x; y++) { keyValues[y] = mergeTab.Rows[p][keyFields[y].ToString()]; } DataRow locRow = ((InfoDataSet)bs.GetDataSource()).RealDataSet.Tables[0].Rows.Find(keyValues); if (locRow != null) { int a = bs.List.Count; for (int b = 0; b < a; b++) { if (((DataRowView)bs.List[b]).Row == locRow) { // 2006/08/05 將View BindingSource.Relation.Active設 為False,Find()完後, 再設為True if (infoRel.Active) { RelationsActive = true; infoRel.Active = false; } // 2006/08/05 //2008/9/4 modified by ccm在新增的時候會插入最後一筆,導致取下一批資料 bs.CancelPositionChanged = true; bs.Position = b; bs.CancelPositionChanged = false; break; } } } } } break; } } } } } }
void FillAllForSelectedBeitrag (String OutsideDefinedBeitragID) { String UsedBeitragID = String.Empty; if (String.IsNullOrEmpty (OutsideDefinedBeitragID)) { if (String.IsNullOrEmpty (SelectedBeitragID)) { ClearAllForSelectedBeitrag (); return; } UsedBeitragID = SelectedBeitragID; } else UsedBeitragID = OutsideDefinedBeitragID; m_GetBeitragButton.IsEnabled = true; m_AktuellerBeitrag = DataBase.GetAllForBeitrag(ActuallSenderName, UsedBeitragID, true, false, false); //TODO //List<String> selectedStatementsForPreLoad = null; //Data.DbServer3.WPMedia.PreLoadAllFirstLevelForOneBeitrag(Guid.Parse(UsedBeitragID), out selectedStatementsForPreLoad); //m_AktuellerBeitrag = Data.DbServer3.WPMedia; //m_ProgrammIndependentDataSet = Data.DbServer3.WPMedia; if (m_AktuellerBeitrag == null) { MessageBox.Show ("Der gewählte Beitrag ist nicht vorhanden"); return; } CheckForDataCompleteness (m_AktuellerBeitrag.Tables ["Beitraege"].Rows [0]); AktuellerBeitragView = new DataView (m_AktuellerBeitrag.Tables ["Beitraege"]) [0]; m_StatistikZuordnungen = new CVM.ConnectorSupport (); m_StatistikZuordnungen.AttributeTable = m_ProgrammIndependentDataSet.Tables ["ZuordnungenTable"]; //ToDo ZuordnungenTable m_StatistikZuordnungen.ConnectorTable = m_AktuellerBeitrag.Tables ["BeitraegeZuZuordnungen"]; m_StatistikZuordnungen.IDDBNameinAttributeTable = "ID"; m_StatistikZuordnungen.EntryNameDBNameinAttributeTable = "Name"; m_StatistikZuordnungen.ConnectorIDDBNameInConnectorTable = "ID"; m_StatistikZuordnungen.ConnectToIDDBNameInConnectorTable = "BeitragID"; m_StatistikZuordnungen.ConnectorAttributeIDDBNameInConnectorTable = "ZuordnungID"; m_StatistikZuordnungen.RootIDToConnectTo = UsedBeitragID; m_SendungsZuordnungen = new CVM.ConnectorSupport (); m_SendungsZuordnungen.AttributeTable = m_ProgrammIndependentDataSet.Tables ["Sendungen"]; m_SendungsZuordnungen.ConnectorTable = m_AktuellerBeitrag.Tables ["BeitraegeZuSendungen"]; m_SendungsZuordnungen.IDDBNameinAttributeTable = "SendungID"; m_SendungsZuordnungen.EntryNameDBNameinAttributeTable = "Name"; m_SendungsZuordnungen.ConnectorIDDBNameInConnectorTable = "BeitraegeZuSendungenID"; m_SendungsZuordnungen.ConnectToIDDBNameInConnectorTable = "BeitragID"; m_SendungsZuordnungen.ConnectorAttributeIDDBNameInConnectorTable = "SendungID"; m_SendungsZuordnungen.RootIDToConnectTo = UsedBeitragID; CVM.ConnectorSupport.SetTextBoxBinding (AktuellerBeitragView, m_BeitragName, "Name"); CVM.ConnectorSupport.SetTextBoxBinding (AktuellerBeitragView, m_ShortDescription, "ShortDescription"); CVM.ConnectorSupport.SetTextBoxBinding (AktuellerBeitragView, m_LongDescription, "LongDescription"); m_ControlFactory.AddDataBaseDefinedProcessing (m_LongDescription, AktuellerBeitragView.Row.Table.TableName, "LongDescription", null, true); CVM.ConnectorSupport.SetTextBoxBinding (AktuellerBeitragView, m_BeitragsWWW, "BeitragsWWW"); m_ControlFactory.AddDataBaseDefinedProcessing (m_BeitragsWWW, AktuellerBeitragView.Row.Table.TableName, "BeitragsWWW", null, true); CVM.ConnectorSupport.SetTextBoxBinding (AktuellerBeitragView, m_BeitragsKontakt, "BeitragsKontakt"); m_ControlFactory.AddDataBaseDefinedProcessing (m_BeitragsKontakt, AktuellerBeitragView.Row.Table.TableName, "BeitragsKontakt", null, true); CVM.ConnectorSupport.SetDatePickerBinding (AktuellerBeitragView, m_Reihenfolge, "BeitragsReihenfolgeInSendung"); if (m_AktuellerBeitrag.GetChanges( ) != null) //Because of undefineable and randomly shown behavioir m_AktuellerBeitrag.Tables ["Beitraege"].AcceptChanges (); m_BeitragsType.ItemsSource = WMB.Basics.GetStringListFromDataTableColumn (m_ProgrammIndependentDataSet.Tables ["BeitragsTypenTable"].Select ("", "BeitragsTyp"), "BeitragsTyp"); //TODO BeitragsTypenTable CVM.ConnectorSupport.SetComboBoxBinding (AktuellerBeitragView, m_BeitragsType, "BeitragsTyp"); //WMB.TableContentDefinition SpecialFieldProcessing = m_ControlFactory.GetSpecialFieldProcessing //(AktuellerBeitragView.Row.Table.TableName, "Author", null, true); m_Authoren.ItemsSource = WMB.Basics.GetStringListFromDataTableColumn (m_ProgrammIndependentDataSet.Tables ["AutorenTable"].Select ("", "Name"), "Name"); CVM.ConnectorSupport.SetLocalComboBoxBinding (this, m_Authoren, "AuthorText"); //TODO AutorenTable m_StatistikZuordnungen.FillConnections (m_BeitragsStatistik); m_SendungsZuordnungen.FillConnections (m_BeitragsSendugsZuordnungen); m_TimingsControl.DoNotExternalDataAccess = true; m_TimingsControl.m_TimingsDataSet = m_AktuellerBeitrag; m_TimingsControl.m_TimingsTypenDataSet = m_ProgrammIndependentDataSet; m_TimingsControl.ConnectedID = UsedBeitragID; m_TimingsControl.ConnectedType = "Beitrag"; m_TimingsControl.ZuordnungsID = ActuallSenderID; m_TimingsControl.DataAccess = m_DataBase; CVM.ConnectorSupport.SetPropertiesControlBinding (AktuellerBeitragView, m_PropertiesControl, "BeitragProperties"); m_PropertiesControl.ShowData (); m_MaterialsControl.DoNotExternalDataAccess = true; m_MaterialsControl.ConnectorTable = m_AktuellerBeitrag.Tables ["VideoFilesZuBeitraege"]; m_MaterialsControl.AttributeTable = m_AktuellerBeitrag.Tables ["VideoFiles"]; m_MaterialsControl.ArchivePathTable = m_ProgrammIndependentDataSet.Tables ["PhysicalArchivePathsTable"]; m_MaterialsControl.ConnectedID = UsedBeitragID; m_MaterialsControl.DataAccess = m_DataBase; m_MaterialsControl.RootIDToConnectTo = UsedBeitragID; m_MaterialsControl.MaterialTypeToSearchFor = m_AktuellerBeitrag.Tables ["Beitraege"].Rows [0] ["BeitragsTyp"].ToString (); m_MaterialsControl.ShowData (); m_PicturesControl.BildVorhanden = m_AktuellerBeitrag.Tables ["Beitraege"].Rows [0] ["BildVorhanden"].ToString (); m_PicturesControl.BeitragID = UsedBeitragID; m_DeleteBeitragButton.IsEnabled = true; SetBeitragLoaded (); }
protected void cmd_Save_Click1(object sender, EventArgs e) { if (txt_roleId.Text.Length == 0) { ShowPageMsg("請輸入角色代號"); return; } if (txt_roleName.Text.Length == 0) { ShowPageMsg("請輸入角色名稱"); return; } if (hidden_Action.Value.Equals("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"] = txt_roleId.Text; DR["Role_Name"] = txt_roleName.Text; DS.Tables[0].Rows.Add(DR); DataSet _changed = DS.GetChanges(); if (region.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]["Role_Name"] = txt_roleName.Text; if (region.Update(ds)) { ReDirect("修改成功"); } else { ReDirect("修改失敗"); } } } }