Wisch10
✅ Convert null datetime error in sqlite myReader
anyone know how to fix an issue with pulling a null datetime from sqlite into myReader? it keeps throwing an error that '' is an invalid string. I even put in a case like (myReader["columnName"].ToString() != null) ? Convert.ToDateTime(myReader["columnName"].ToString()) : Convert.ToDateTime(null) and that does not work
16 replies
✅ SQLite Data Insert locks up database
I am working on a project of mine and I can get my application to create the database and its tables but when I try to insert the first set of data to populate the base data, it locks the database.
public static void PopulateDBVersionTable()
{
using SQLiteConnection sqliteConn = CreateConnection();
sqliteConn.Open();
using DbTransaction dbTrans = sqliteConn.BeginTransaction();
try
{
string sql = "Insert Into tblDBVersion (dbVersion, dbBuild) values (0,100)";
using (var command = new SQLiteCommand(sql, sqliteConn))
{
command.ExecuteNonQuery();
}
dbTrans.Commit();
}
catch (Exception ex)
{
dbTrans.Rollback();
MessageBox.Show(ex.Message, "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (sqliteConn.State == ConnectionState.Open)
{
sqliteConn.Close();
}
}
}
Any help refactoring this so that it doesn't lock up on me would be great7 replies
Is there a way to return or access a class object created inside a public partial class (form) from
I have a process that allows expenses to be added from a form, and a separate process to add an asset from a form. I would like to add a combination of the two if the expense is for an asset but to run the db inserts in the same function so that if one fails, both are rolled back. I created my second asset form to accept the values for price, purchase date, and payment type and have that only being generated when the expense type is an asset.
FrmAssetFromExpense frmAssetFromExpense = new(expenseDate, amount, type);
fromAssetFromExpense.ShowDialog();
Inside the new form for asset addition, all the items are in place to create the Asset class object from the values entered on the form.
Is there a way to return that Asset object to the main expense form to run a single sql insert?
20 replies