public bool LoadData(EasyQuery qry) { listBox1.Items.Clear(); if (qry != null) { FieldList fl = qry.Fields; if (fl != null) { int n; for (int i = 0; i < fl.Count; i++) { if (EPField.IsDatetime(fl[i].OleDbType)) { n = listBox1.Items.Add(fl[i]); if (fl[i].OleDbType == System.Data.OleDb.OleDbType.DBTimeStamp) { listBox1.SelectedIndex = n; chkTS.Checked = true; } } } } } return(listBox1.Items.Count > 0); }
public static int GetOleDbTypeIndex(OleDbType type) { if (type == System.Data.OleDb.OleDbType.BigInt || type == System.Data.OleDb.OleDbType.UnsignedBigInt ) { return(FLD_Long_integer); } else if (EPField.IsInteger(type)) { return(FLD_Integer); } else if (type == System.Data.OleDb.OleDbType.Currency) { return(FLD_Currency); } else if (EPField.IsNumber(type)) { return(FLD_Decimal); } else if (EPField.IsDatetime(type)) { if (type == System.Data.OleDb.OleDbType.DBTimeStamp) { return(FLD_Date_time); } else if (type == OleDbType.DBTime) { return(FLD_Time); } else { return(FLD_Date); } } else if (type == System.Data.OleDb.OleDbType.Boolean) { return(FLD_Bool); } else if (type == System.Data.OleDb.OleDbType.LongVarChar || type == System.Data.OleDb.OleDbType.LongVarWChar) { return(FLD_Text); } else if (type == System.Data.OleDb.OleDbType.Binary || type == System.Data.OleDb.OleDbType.LongVarBinary || type == System.Data.OleDb.OleDbType.VarBinary ) { return(FLD_Binary); } else if (EPField.IsString(type)) { return(FLD_String); } else { return(FLD_Unknown); } }
public void StartWithParameterValues(params object[] values) { if (values != null && values.Length > 0) { FieldList pl = Parameters; if (pl != null) { int n = Math.Min(pl.Count, values.Length); for (int i = 0; i < n; i++) { if (values[i] is DateTime) { if (!EPField.IsDatetime(pl[i].OleDbType)) { pl[i].OleDbType = OleDbType.DBTimeStamp; } if (this.IsJet) { DateTime dt = (DateTime)values[i]; pl[i].SetValue(new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second)); } else { pl[i].SetValue(values[i]); } } else { if (values[i] == null || values[i] == DBNull.Value) { pl[i].OleDbType = OleDbType.VarWChar; pl[i].SetValue(null); } else { pl[i].OleDbType = EPField.ToOleDBType(values[i].GetType()); pl[i].SetValue(values[i]); } } } } } startDT(); }
public virtual string Execute() { string sMsg = string.Empty; SetError(sMsg); _affectedRows = 0; if (_sql != null && connect != null) { DbCommand cmd = connect.ConnectionObject.CreateCommand(); if (_transaction != null) { cmd.Transaction = _transaction; } bool bClosed = !connect.ConnectionObject.Opened; if (bClosed) { connect.ConnectionObject.Open(); } if (connect.ConnectionObject.Opened) { try { int i; EnumParameterStyle pstyle = connect.ParameterStyle; FieldList pmMap = new FieldList(); string s; int nCount; s = _sql.GetSQLStatement(pmMap, pstyle); if (pstyle == EnumParameterStyle.QuestionMark) { nCount = pmMap.Count; } else { nCount = _sql.ParamCount; } connect.Log("Command:{0}, params:{1}", s, nCount); cmd.CommandText = s; cmd.CommandType = CommandType.Text; for (i = 0; i < nCount; i++) { DbParameter pam = cmd.CreateParameter(); EPField f; if (pstyle == EnumParameterStyle.QuestionMark) { f = pmMap[i]; pam.ParameterName = "@P" + i.ToString(); } else { f = _sql.Parameters[i]; pam.ParameterName = ParameterList.GetParameterName(pstyle, _sql.Parameters[i].Name); } pam.DbType = ValueConvertor.OleDbTypeToDbType(f.OleDbType); pam.Size = f.DataSize; OleDbParameter op = pam as OleDbParameter; if (op != null && f.OleDbType == OleDbType.DBTimeStamp) { if (f.Value != null && f.Value != DBNull.Value) { DateTime dt = (DateTime)(f.Value); dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); f.SetValue(dt); } } connect.Log("param{0}:{1},{2},{3}. Value type:{4}. Value:{5}", i, pam.ParameterName, pam.DbType, pam.Size, f.OleDbType, f.Value); if (EPField.IsDatetime(f.OleDbType)) { if (f.IsNullOrEmpty) { pam.Value = System.DBNull.Value; } else { object dt0 = ValueConvertor.ConvertByOleDbType(f.Value, f.OleDbType); try { DateTime dt = (DateTime)dt0; if (dt.Ticks == 0) { pam.Value = System.DBNull.Value; } else { pam.Value = dt; } } catch { pam.Value = dt0; } } } else { pam.Value = ValueConvertor.ConvertByOleDbType(f.Value, f.OleDbType); } cmd.Parameters.Add(pam); } _affectedRows = cmd.ExecuteNonQuery(); connect.Log("Affected rows:{0}", _affectedRows); if (bClosed) { closeConnections(); } if (this.ExecuteFinish != null) { ExecuteFinish(this, EventArgs.Empty); } if (_webPage != null && !string.IsNullOrEmpty(_name)) { _webPage.SetServerComponentName(_name); } } catch (Exception er) { if (_transaction != null) { _transaction.Rollback(); _transaction.Dispose(); _transaction = null; connect.Log("rollback with error {0}", er.Message); throw; } else { sMsg = ExceptionLimnorDatabase.FormExceptionText(er); } } finally { if (bClosed) { if (connect.ConnectionObject.State != ConnectionState.Closed) { connect.ConnectionObject.Close(); } } } } else { sMsg = "Database connection not set"; } } else { sMsg = "SQL statement not set"; } if (!string.IsNullOrEmpty(sMsg)) { SetError(sMsg); if (connect != null) { connect.Log("Error executing EasyUpdator.Execute. {0}", sMsg); } } return(sMsg); }
public void LoadData(DataGridViewColumnCollection cols) { _cols = cols; _tbl = new DataTable(); _tbl.Columns.Add("ColumnName", typeof(string)); _tbl.Columns[0].ReadOnly = true; _tbl.Columns.Add("HeaderText", typeof(string)); _tbl.Columns.Add("DataType", typeof(string)); for (int i = 0; i < cols.Count; i++) { OleDbType t = OleDbType.VarWChar; if (cols[i].ValueType != null) { t = EPField.ToOleDBType(cols[i].ValueType); } string tx; if (t == OleDbType.DBTime) { tx = "Time"; } else if (EPField.IsDatetime(t)) { tx = "DateTime"; } else if (EPField.IsInteger(t)) { tx = "Integer"; } else if (EPField.IsNumber(t)) { tx = "Decimal"; } else if (EPField.IsBoolean(t)) { tx = "Boolean"; } else { tx = "Text"; } string s = cols[i].DataPropertyName; if (string.IsNullOrEmpty(s)) { s = cols[i].HeaderText; if (string.IsNullOrEmpty(s)) { s = cols[i].Name; } } string sh = cols[i].HeaderText; if (string.IsNullOrEmpty(sh)) { sh = cols[i].DataPropertyName; if (string.IsNullOrEmpty(sh)) { sh = cols[i].Name; } } _tbl.Rows.Add(s, sh, tx); } dataGridView1.AllowUserToAddRows = false; dataGridView1.AllowUserToDeleteRows = false; dataGridView1.AllowUserToOrderColumns = false; dataGridView1.AllowUserToResizeRows = false; dataGridView1.Columns.Clear(); dataGridView1.AutoGenerateColumns = true; dataGridView1.DataSource = _tbl; dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable; }