protected void edit_mode() { conn = new MyConnection(); string strcmd = "select * from [HMC_PkgRelative] Where ID = " + strQueID; SqlCommand cmd = new SqlCommand(strcmd); DataTable dt = conn.GetData(cmd); if (dt.Rows.Count > 0) { strPkgCode = dt.Rows[0].Field <string>("PkgCode"); if (dt.Rows[0].Field <Decimal>("Type") == 1) { type_list.SelectedValue = "1"; pkg_panel.Attributes.Add("style", "visibility:visible"); txtPkgCode.Text = strPkgCode; } else { type_list.SelectedValue = "0"; pkg_panel.Attributes.Add("style", "visibility:hidden"); } txtName.Text = dt.Rows[0].Field <string>("Name"); } conn.Dispose(); }
protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
public void changeoperator(string AirlinePrefix, string MAWBNumber, string operatorname, StreamWriter strWriter) { try { System.Data.OleDb.OleDbConnection MyConnection = null; System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(); if (Trackername.Contains("NEW")) { //new tracker MyConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=2;RetrieveIds=Yes; DATABASE=http://klsstg03/pingSD/Support/;LIST={DEFD5BEC-D6A2-400E-9F98-8F6E653A2CE9};VIEW={CC4F76AA-FA1B-44D7-9611-665077F0E451};"); //tracker new MyConnection.Open(); } else if (Trackername.Contains("OLD")) { //old tracker MyConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=2;RetrieveIds=Yes; DATABASE=http://klsstg03/pingSD/;LIST={5D0E59F0-E498-4EF0-BBC1-C2FCF7C9150F};VIEW={87B39BBA-9465-4B2E-87D1-FE88E735EEA6};"); //tracker old MyConnection.Open(); } myCommand.Connection = MyConnection; string DateStamp = System.DateTime.Now.ToString("dd/MM/yyyy H:mm"); string sql = "Update [Table1] set Operator='" + operatorname + "' where Pfx='" + AirlinePrefix + "' AND AWB_No='" + MAWBNumber + "' AND Shipment_Status='2 - Ack'"; //, PDF_Sent_At = '" +DateStamp + "' myCommand.CommandText = sql; myCommand.ExecuteNonQuery(); sql = ""; MyConnection.Close(); MyConnection.Dispose(); Console.WriteLine("Status updated successfully for AWB " + MAWBNumber + ".\n"); Console.WriteLine("Status updated successfully for AWB " + MAWBNumber + ".\n"); strWriter.WriteLine(AirlinePrefix + "-" + MAWBNumber + " status Updated successfully as '4 - Updated in PING'"); strWriter.WriteLine(" "); strWriter.WriteLine("-------------------------------------------------------"); strWriter.WriteLine(" "); if (MyConnection.State == ConnectionState.Open) { MyConnection.Close(); MyConnection.Dispose(); } } catch (Exception ex) { Console.WriteLine(ex.Message); strWriter.WriteLine(MAWBNumber + " could not be Updated " + ex.Message); strWriter.WriteLine(" "); strWriter.WriteLine("-------------------------------------------------------"); strWriter.WriteLine(" "); } }
public async Task SubclassDisposeKillsHttpClientAndCallsOwnDispose() { var connection = new MyConnection(endpoint, UserName, Password); Assert.Null(connection.Disposing); connection.Dispose(); await Assert.ThrowsAsync <NullReferenceException>(() => connection.HttpClient.GetAsync(new Uri("http://something.com"))); Assert.Equal(connection.Disposing, true); }
protected void BindGrid() { try { string strSql = "Select RunDown_ID,Seq_No From [HMC_PkgRunDown] Where Pkg_Id = '" + strQuePkgId + "' order by seq_no"; SqlCommand cmd = new SqlCommand(strSql); conn = new MyConnection(); DataTable dt = conn.GetData(cmd); dt.Columns.Add("Name", typeof(string)); if (dt.Rows.Count == 0) { dt.Rows.Add(); } else { foreach (DataRow row in dt.Rows) //細項名稱 { string strRunDounID = row["RunDown_ID"].ToString(); using (conn = new MyConnection()) { string strSql1 = "Select Name From [HMC_RunDown] Where Id = @Id"; SqlCommand cmd1 = new SqlCommand(strSql1); cmd1.Parameters.Add("Id", SqlDbType.Int).Value = int.Parse(strRunDounID); DataTable dt1 = conn.GetData(cmd1); if (dt1.Rows.Count > 0) { row["Name"] = dt1.Rows[0].Field <string>("Name"); } else { string strmsg = string.Format("代碼{0},資料庫中無此流程", strRunDounID); PublicLib.showAlert(strmsg); } cmd1.Cancel(); conn.Dispose(); } } } ViewState["Pkg_Rundown"] = dt; GridView1.DataSource = dt; GridView1.DataBind(); } catch (Exception ex) { PublicLib.handleError("", this.GetType().Name, ex.Message); } }
public async Task SubclassDisposeKillsHttpClientAndCallsOwnDispose() { var connection = new MyConnection(endpoint, UserName, Password); Assert.Null(connection.Disposing); connection.Dispose(); await Assert.ThrowsAsync<NullReferenceException>(() => connection.HttpClient.GetAsync(new Uri("http://something.com"))); Assert.Equal(connection.Disposing, true); }