Reputation: 1630
I am trying to create a .NET application that will be storing information in a SQLite file. The issue I am running into is once the SQL command is executed, there is only one record visible, as if the current row is being overwritten.
Table creation:
bool pathExist = Directory.Exists(appdataPath + "OnCallDB.sqlite");
if (!pathExist)
{
SQLiteConnection.CreateFile(appdataPath + "OnCallDB.sqlite");
SQLiteConnection dbNewConnection = new SQLiteConnection("Data Source=" + appdataPath + "OnCallDB.sqlite;Version=3;");
dbNewConnection.Open();
string sqlTableCreation = "CREATE TABLE Calls (Id Integer PRIMARY KEY, name varchar(30), ticket varchar(20), phone varchar(20), day varchar(20), start_time varchar(20), end_time varchar(20), raw_time varchar(20), weighted_time varchar(20), date DATETIME, notes varchar(255))";
SQLiteCommand command = new SQLiteCommand(sqlTableCreation, dbNewConnection);
command.ExecuteNonQuery();
dbNewConnection.Close();
}
Insert statement:
SQLiteCommand insertCommand = new SQLiteCommand("INSERT INTO Calls ([name], [ticket], [phone], [day], [start_time], [end_time], [raw_time], [weighted_time], [date], [notes])"+
"VALUES(@name, @ticket, @phone, @day, @start_time, @end_time, @raw_time, @weighted_time, @date, @notes)",connection);
insertCommand.Parameters.AddWithValue("@name", name);
insertCommand.Parameters.AddWithValue("@ticket", ticket);
insertCommand.Parameters.AddWithValue("@phone", phone);
insertCommand.Parameters.AddWithValue("@day", day);
insertCommand.Parameters.AddWithValue("@start_time", start_time);
insertCommand.Parameters.AddWithValue("@end_time", end_time);
insertCommand.Parameters.AddWithValue("@raw_time", raw_time);
insertCommand.Parameters.AddWithValue("@weighted_time", weighted_time);
insertCommand.Parameters.AddWithValue("@date", date);
insertCommand.Parameters.AddWithValue("@notes", notes);
try
{
connection.Open();
insertCommand.ExecuteNonQuery();
connection.Close();
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
I have ran the command manually to the SQL file and inserts a new row. When I run the above SQLite command, it replaces the row. As far as I can tell. I have looked at the file creation date and time and it appears that the file is just being modified and not replaced.
Upvotes: 1
Views: 952
Reputation: 1630
The issue was not with the SQL statement. The issue was with how the file was being created
Upvotes: 1