I have a Windows Form in Visual Studio that is connected to a MS Access Database. The application is supposed to allow the user to type a report into a text box and save that data along with a time stamp as a record in the database. Everything seems to be working on the application end but the data isn't being saved or isn't showing up in the database.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
namespace CapstoneProjectDataEntryApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void SubmitBtn_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\Users\Austin\Documents\School\CapstoneProjectDataEntryApp\ShabelReports.accdb";
try
{
conn.Open();
string myEntry = EntryTB.Text;
string myDateTime = DateTime.Now.ToString();
string myQuery = "INSERT INTO ProgressReports (Report, DateTime) VALUES ('" + myEntry + "','" + myDateTime + "')";
OleDbCommand cmd = new OleDbCommand(myQuery, conn);
cmd.ExecuteNonQueryAsync();
MessageBox.Show("Data saved successfully!");
}
catch(Exception ex)
{
MessageBox.Show("Failed due to" + ex.Message);
}
finally
{
conn.Close();
EntryTB.Text = "";
}
}
}
}
I have tried just using the database as a data source, and just as a data connection, and both, and all have the same result. I'm new to what I'm doing so I don't know much about working with databases in Windows Forms