public static UsuariosBO UpdateUsuario(UsuariosBO Usuario, ADODB.Connection cn) { var RsUsuarios = new ADODB.Recordset(); var LibORGM = new SQL(); var Serializer = new SerializerFO(); try { RsUsuarios.Open(String.Format("SELECT * FROM dbo.Usuarios WHERE Usuario = '{0}'", Usuario.Usuario), cn, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic); if (RsUsuarios.EOF) { RsUsuarios.AddNew(); RsUsuarios.Fields["Usuario"].Value = Usuario.Usuario; RsUsuarios.Fields["SenhaAcesso"].Value = Usuario.SenhaAcesso; RsUsuarios.Fields["TokenAcesso"].Value = CriptografiaFO.EncriptarMD5(Usuario.TokenAcesso); } RsUsuarios.Fields["Inativo"].Value = Usuario.Inativo; RsUsuarios.Update(); RsUsuarios.Close(); Usuario = UsuariosDA.GetUsuarios(Usuario.Usuario, cn); } catch (Exception) { throw; } return(Usuario); }
protected override void InternalInsert(string[] names, object[] values) { _recordset.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value); for (int index = 0; index < names.Length; index++) { _recordset.Fields[names[index]].Value = values[index]; } _recordset.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value); }
private void save_form() { try { //ADOconn.BeginTrans(); ADODB.Recordset cus = new ADODB.Recordset(); //ADOconn.BeginTrans(); if (cmbgrp.Text == "") { MessageBox.Show("Invalid User Group", "Invalid Entry"); return; } dgv1.EndEdit(); ADODB.Connection ADOconn = new ADODB.Connection(); ADOconn.Open("Provider=SQLOLEDB;Initial Catalog= " + decoder.InitialCatalog + ";Data Source=" + decoder.DataSource + ";", decoder.UserID, decoder.Password, 0); for (int i = 1; i < dgv1.RowCount; i++) { if (dgv1["id", i].Value == null) { continue; } cus = new ADODB.Recordset(); sql = "SELECT * FROM userpriv where GROUP_NAME ='" + cmbgrp.Text + "' and form_id=" + dgv1["id", i].Value; cus.Open(sql, ADOconn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, -1); if (cus.RecordCount == 0) { cus.AddNew(); } cus.Fields["GROUP_NAME"].Value = cmbgrp.Text; cus.Fields["form_id"].Value = dgv1["id", i].Value; cus.Fields["ins"].Value = dgv1["ins", i].Value; cus.Fields["upd"].Value = dgv1["upd", i].Value; //cus.Fields["qry"].Value = dgv1["qry",i].Value; cus.Fields["del"].Value = dgv1["del", i].Value; cus.Fields["dsp"].Value = dgv1["dsp", i].Value; cus.Fields["Menu_Name"].Value = dgv1["Menu_Name", i].Value; cus.Update(); } string grp = cmbgrp.Text; sql = "SELECT distinct group_name FROM UserPriv "; SqlDataAdapter adagrp = new SqlDataAdapter(sql, Conn); ///ada.TableMappings.Add("Table", "Leaders"); DataSet grpds = new DataSet(); adagrp.Fill(grpds, "UserPriv"); cmbgrp.DisplayMember = "group_name"; cmbgrp.DataSource = grpds.Tables[0]; cmbgrp.Text = grp; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void UpdateADODBRecordset_from_ADODataTable(DataTable inTable, ref ADODB.Recordset adoRs) { ADODB.Fields adoFields = adoRs.Fields; System.Data.DataColumnCollection inColumns = inTable.Columns; //Delete if (adoRs.RecordCount > 0) { adoRs.MoveFirst(); } while (!adoRs.EOF) { adoRs.Delete(); adoRs.MoveNext(); } //Add foreach (DataRow dr in inTable.Rows) { // Proceso las que no estan borradas if (dr.RowState != DataRowState.Deleted) { adoRs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value); for (int columnIndex = 0; columnIndex < inColumns.Count; columnIndex++) { ADODB.Field field = adoFields[columnIndex]; try { adoFields[columnIndex].Value = dr[columnIndex]; } catch (Exception ex) { string message = string.Format("Error al actualizar la columna {0}.{1}: {2}", inTable.TableName, field.Name, ex.Message); throw new XTangoException(message); } } } } }
public void MegaInsertAdo() { var con = new Connection(); con.Open("Provider='sqloledb';Data Source='(local)';Initial Catalog='Proba';Integrated Security='SSPI';"); var rec = new Recordset(); rec.Open("SELECT s1,s2 FROM Tabl2", con, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockOptimistic, 0); for (int i = 1; i <= 10000; ++i) { //string [] f={"s1","s2"}; int[] f = { 0, 1 }; string [] v = { "s1", "s2" }; rec.AddNew(f, v); //rec.Fields["s2"].Value = i.ToString(); //rec.Fields["s2"].Value = "new"; rec.Update(f, v); } rec.Close(); con.Close(); }
public static ADODB.Recordset ConvertToRecordset(DataTable dt) { ADODB.Recordset rs = new ADODB.Recordset(); rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient; ADODB.Fields RsFld = rs.Fields; System.Data.DataColumnCollection DtCols = dt.Columns; foreach (DataColumn DtCol in DtCols) { RsFld.Append(DtCol.ColumnName , CAdo.ConvertDotNetTypeToAdoType(DtCol.DataType) , DtCol.MaxLength , DtCol.AllowDBNull ? ADODB.FieldAttributeEnum.adFldIsNullable : ADODB.FieldAttributeEnum.adFldUnspecified , null); } rs.Open(System.Reflection.Missing.Value , System.Reflection.Missing.Value , ADODB.CursorTypeEnum.adOpenStatic , ADODB.LockTypeEnum.adLockOptimistic, 0); foreach (DataRow dr in dt.Rows) { rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value); for (int cl = 0; cl < DtCols.Count; cl++) { RsFld[cl].Value = dr[cl]; } } return(rs); }
static ADODB.Recordset ConvertToRecordset(DataTable inTable) { ADODB.Recordset result = new ADODB.Recordset(); result.CursorLocation = ADODB.CursorLocationEnum.adUseClient; ADODB.Fields resultFields = result.Fields; System.Data.DataColumnCollection inColumns = inTable.Columns; foreach (DataColumn inColumn in inColumns) { resultFields.Append(inColumn.ColumnName , TranslateType(inColumn.DataType) , inColumn.MaxLength , inColumn.AllowDBNull ? ADODB.FieldAttributeEnum.adFldIsNullable : ADODB.FieldAttributeEnum.adFldUnspecified , null); } result.Open(System.Reflection.Missing.Value , System.Reflection.Missing.Value , ADODB.CursorTypeEnum.adOpenStatic , ADODB.LockTypeEnum.adLockOptimistic, 0); foreach (DataRow dr in inTable.Rows) { result.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value); for (int columnIndex = 0; columnIndex < inColumns.Count; columnIndex++) { resultFields[columnIndex].Value = dr[columnIndex]; } } return result; }
public int Count; // counts # times run then erases database -- nothing in it... a.mdb !! public float RunSql2(string str1, short level1) { //on error GoTo err_RunSql2; ADODB.Recordset reccust = null; short ret; int i; float retval; string str2; retval = -1; if (globaldb_a == null) { try { if (!File.Exists("a.xxx")) { File.Copy(DbUse.GetMainDirectory() + "App_Data\\" + "a.xxx", varlocal + "a.xxx"); } if (!File.Exists("b.xxx")) { File.Copy(DbUse.GetMainDirectory() + "App_Data\\" + "b.xxx", varlocal + "b.xxx"); } } catch (Exception) { } globaldb_a = new ADODB.Connection(); Count = 0; } else { Count++; DbUse.CloseAdo(globaldb_a); } if (Count > 2000) { try { File.Copy("b.xxx", "a.xxx", true); Count = 0; } catch (Exception) { } } DbUse.open_ado(ref globaldb_a, "a.xxx"); // DOES A CONVERSION OF AN EXPRESSION (6+7*4) TO A NUMBER... if ((str1.Trim() == "'") | (str1.Trim() == ".") | (str1.Trim() == ",")) { retval = (float)0.0; return(retval); } str2 = "SELECT tbldummy.GeneralID, " + str1 + " AS a1 FROM tbldummy;"; DbUse.open_ado_rec(globaldb_a, ref reccust, str2); try { // xxx tomorrow on run times += <> /()*., no '"?:;[]{}|&!@#$%^& NO: [0-31] 33-39 42 58,59 63 64 91-96 123-127 retval = (float)(double.Parse(reccust.Fields["a1"].Value.ToString())); } catch (Exception e) { // ERRORMSG tomorrow //MyUtilities.MsgBox("Error in solving Operation Time/Data Equation: " + conn.ConnectionString + " (" + e.Message + ")"); string str3; str3 = e.Message; //retval = (float) -777.0; retval = float.NaN; } finally { DbUse.CloseAdoRec(reccust); DbUse.CloseAdo(globaldb_a); //gwwdd adding error here !!! if (float.IsNaN(retval) || retval < -100) { try { DbUse.open_ado_rec(globaldb, ref reccust, "zstblerrors"); reccust.AddNew(); if (Oper_err_id > 0) { reccust.Fields["Level"].Value = 0; // Error; calc_return |= ERR_FLAG; reccust.Fields["Table"].Value = "Operations"; string errorMsg = " Product " + Part_err_name + " Operation " + Oper_err_name + " has an operation time which is not a number. "; if (!inOperRoutingPages) { errorMsg += "Go to Product Operations/Routing Page, hit the [Show Real Times] button and look for field value NaN."; } else { errorMsg += "Look for field value NaN."; } reccust.Fields["Text"].Value = errorMsg; reccust.Fields["mpxFlag"].Value = -1; reccust.Fields["partid"].Value = Part_err_id; reccust.Fields["operid"].Value = Oper_err_id; reccust.Fields["Wid"].Value = glngwid; reccust.Update(); } else { // ROUTING DATA ERROR. reccust.Fields["Level"].Value = 0; // Error; calc_return |= ERR_FLAG; reccust.Fields["Table"].Value = "Routing"; string errorMsg = " Product " + Part_err_name + " FROM Operation " + Oper_err_name + " has an % routing value that is not a number. "; if (!inOperRoutingPages) { errorMsg += "Go to Product Operations/Routing Page, Scroll down to the ROUTING AREA hit the [Show Real Percentage] button and Look for field value NaN. "; } else { errorMsg += "Look for field value NaN."; } reccust.Fields["Text"].Value = errorMsg; reccust.Fields["mpxFlag"].Value = -1; reccust.Fields["partid"].Value = Part_err_id; reccust.Fields["operid"].Value = -1 * Oper_err_id; reccust.Fields["Wid"].Value = glngwid; reccust.Update(); } } catch (Exception exp) { LogFiles logFiles = new LogFiles(this.username); logFiles.ErrorLog(exp); } finally { DbUse.CloseAdoRec(reccust); } } } return(retval); //err_RunSql2: /*if (level1 == 1) * { * retval = -999; * return retval; //exit Function; * };*/ /* if ((Err.Number == 3075)) * { * //parathesis problem; * // msgbox("Error in evaluating string " + str1 + " Parathesis Problem? " + ErrorToString() + " Using -999 as the value", 0, appl_name); * * //unsolved parameter; * // msgbox("Error in evaluating string " + str1 + " Unresolved Parameter? " + ErrorToString() + " Using -999 as the value", 0, appl_name); * * //divide by zero error; * // msgbox("Error in evaluating string " + str1 + " Divide by zero error? " + ErrorToString() + " Using -999 as the value", 0, appl_name); * * //a parameter has a null value. Check 'switch' and 'iif'; * // msgbox("Error in evaluating string " + str1 + " Null value! iif or Switch Problem? " + ErrorToString() + " Using -999 as the value", 0, appl_name); * * // msgbox("Error in evaluating string " + str1 + " Unknown Problem? " + ErrorToString() + " Using -999 as the value", 0, appl_name); * retval = -999; * return retval; //exit Function; * }; */ //retval = -999; //return retval; //RESUME NEXT } // end function;