Click here to Skip to main content
15,909,445 members

Comments by aciobanita constantin (Top 13 by date)

aciobanita constantin 28-Apr-16 14:11pm View    
The pice of code were I get the error is new oledbadapder.fill, and is a null reference, only inside the Beck round worker Dowork,
aciobanita constantin 28-Apr-16 14:09pm View    
Is an abstract error, null reference on new oledbadapder.fill
aciobanita constantin 26-Jan-15 3:19am View    
So, on click dgv1 - the dgv2 may have or not record, if dgv2 has record, dgv3 and dgv4 has records, if dgv2 has no record, dgv3 and dgv4 not have record (this is OK), but a succes show the record on dgv2, when i change row from the dgv1 and dgv2 has no records (this can occur and is OK), the dgv3 and dgv4 has the same record from the firs select dgv1, in this situation dgv3 and dgv4 must not have records - how to empy (has datasource), i try with dgv1.Update().
aciobanita constantin 29-Oct-14 13:57pm View    
class MyAccessConnection : DataConnection
{
OleDbConnection Connection;
OleDbCommand Command;
OleDbTransaction OperatieDate;

string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataSource + ";Persist Security Info=True;Jet OLEDB:Database Password=" + Password + ";";
public MyAccessConnection()
{
(Command = new OleDbCommand()).Connection = Connection = new OleDbConnection(ConnectionString);
ConnectionDistructor = new System.Timers.Timer(60000);
GC.KeepAlive(ConnectionDistructor);
}

public override void InceputTranzactie()
{
OperatieDate = Connection.BeginTransaction(IsolationLevel.ReadCommitted);
Command.Connection = Connection;
Command.Transaction = OperatieDate;
}
public override void CommitTranzaction()
{
OperatieDate.Commit();
}
public override void RollBackTranzaction()
{
OperatieDate.Rollback();
}
public override void FillDataTable(DataTable Table, bool Decrypt)
{
ConnectionDistructor.Enabled = false;
if (Connection.State == System.Data.ConnectionState.Closed) Connection.Open();
Status.Text = "1";
try
{
Table.Rows.Clear();
Table.Columns.Clear();
new OleDbDataAdapter(Command).Fill(Table);
//Table.Rows[1].ItemArray;

int StartIndex = 1;
try
{
if (Table.Rows.Count > 0)
Table.Rows[0][0].ToString();
if (Table.Rows.Count > 1)
Table.Rows[1][0].ToString();
}
catch { StartIndex++; }
for (int i = StartIndex; i < Table.Columns.Count; i++) for (int j = 0; j < Table.Rows.Count; j++)
Table.Rows[j][i] = Table.Rows[j][i].ToString();

}
catch (Exception Ex) { throw Ex; }
finally { Command.Parameters.Clear(); ConnectionDistructor.Enabled = true; }
}

public override object ExecuteNonQuery()
{
ConnectionDistructor.Enabled = false;
if (Connection.State == System.Data.ConnectionState.Closed) Connection.Open();
Status.Text = "1";
try
{
return Command.ExecuteNonQuery();
}
catch (Exception Ex) { throw Ex; }
finally { Command.Parameters.Clear(); ConnectionDistructor.Enabled = true; }
}

public override string CommandText
{
set
{
Command.CommandText = value;
}
}

public override void AddParameter(string Name, object Value)
{
AddParameter(Name, Value, true);
}

public override void AddParameter(string Name, object Value, bool Encrypt)
{
Command.Parameters.Add(new OleDbParameter(Name, Value));
}

public override void Open()
{
Connection.Open();
}

public override void Close()
{
Connection.Close();
}
aciobanita constantin 29-Oct-14 13:55pm View    
ok,
public static DataConnection Connection;
[STAThread]
static void Main()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("ro-RO");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ro-RO");

.......


here is the DataConection class:

class DataConnection
{
public System.Timers.Timer ConnectionDistructor;
public static System.Windows.Forms.TextBox Status = new System.Windows.Forms.TextBox();
public static string DataSource = "";
public static string Database = "";
public static string UserName = "";
public static string Password = "";
public static int ConnectionType = -1;
public static int SQLAuthenticationType;

public static void SaveSettings()
{
StreamWriter SW = new StreamWriter(System.Windows.Forms.Application.StartupPath + "\\Setari.dat");
SW.Write(Converter.Encrypt(DataSource));
SW.Write("\n" + Converter.Encrypt(Database));
SW.Write("\n" + Converter.Encrypt(UserName));
SW.Write("\n" + Converter.Encrypt(Password));
SW.Write("\n" + Converter.Encrypt(ConnectionType.ToString()));
SW.Write("\n" + Converter.Encrypt(SQLAuthenticationType.ToString()));
SW.Close(); SW = null;
(Program.Connection = GetConnection()).Open();
Program.Connection.InitialiseDatabase();
}

public static void GetSettings()
{
StreamReader SR = new StreamReader("Setari.dat");
DataSource = Converter.Decrypt(SR.ReadLine());
Database = Converter.Decrypt(SR.ReadLine());
UserName = Converter.Decrypt(SR.ReadLine());
Password = Converter.Decrypt(SR.ReadLine());
ConnectionType = Convert.ToInt32(Converter.Decrypt(SR.ReadLine()));
SQLAuthenticationType = Convert.ToInt32(Converter.Decrypt(SR.ReadLine()));
SR.Close(); SR = null;
}

public static DataConnection GetConnection()
{
if (((ConnectionTypes)ConnectionType) == ConnectionTypes.AccessConnection)
return new MyAccessConnection();
if (((ConnectionTypes)ConnectionType) == ConnectionTypes.MySQLConnection)
return new MySqlConnection(); return new MsSqlConnection();
}

public virtual void AddParameter(string Name, object Value) { }

public virtual void AddParameter(string Name, object Value, bool Encrypt) { }

public virtual void FillDataTable(DataTable Table, bool Decrypt) { }

public virtual string CommandText { set { } }

public virtual object ExecuteNonQuery()
{
return new object();
}

public virtual void Open() { }

public virtual void Close() { }

public virtual void InitialiseDatabase() { }

public virtual void InceputTranzactie() { }
public virtual void CommitTranzaction() { }
public virtual void RollBackTranzaction() { }
}