Моя кнопка при нажатии выглядит следующим образом:
private void button1_Click(object sender, EventArgs e)
{
ticket.Details td = new ticket.Details();
td.@ref = txtRef.Text;
td.subject = txtSubject.Text;
td.contact_name = txtContact_Name.Text;
td.company_name = txtCompany_Name.Text;
td.description = rtDescription.Text;
td.business_impact = rtBusiness_Impact.Text;
td.severity = txtSeverity.Text;
var ticket = new ticket();
ticket.AddTicket(td);
}
AddTicket
выглядит следующим образом:
public int AddTicket(Details details)
{
const string query = "INSERT INTO support(ref, subject, contact_name, company_name, description, business_impact, severity) VALUES (@ref, @subject, @contact_name, @company_name, @description, @business_impact, @severity)";
//here we are setting the parameter values that will be actually
//replaced in the query in Execute method
var args = new Dictionary<string, object>
{
{"@ref", details.@ref},
{"@subject", details.subject},
{"@contact_name", details.contact_name},
{"@company_name", details.company_name},
{"@description", details.description},
{"@business_impact", details.business_impact},
{"@severity", details.severity}
};
return ExecuteWrite(query, args);
}
Когда я смотрю на:
return ExecuteWrite(query, args);
Я вижу, что запрос:
INSERT INTO support(ref, subject, contact_name, company_name, description, business_impact, severity)
VALUES (@ref, @subject, @contact_name, @company_name, @description, @business_impact, @severity)
И аргументы 7
Мой ExecuteWrite
выглядит так:
private int ExecuteWrite(string query, Dictionary<string, object> args)
{
int numberOfRowsAffected;
// setup the connection to the database
using (var con = new SQLiteConnection("Data Source=main.db"))
{
con.Open();
// open a new command
using (var cmd = new SQLiteCommand(query, con))
{
// set the arguments given in the query
foreach (var pair in args)
{
cmd.Parameters.AddWithValue(pair.Key, pair.Value);
}
cmd.Prepare();
// execute the query and get the number of row affected
numberOfRowsAffected = cmd.ExecuteNonQuery();
}
return numberOfRowsAffected;
}
}
Все выглядит хорошо, мой numberOfRowsAffected
показывает 1 строку, а мои аргументы равны 7.
Я не получаю ошибок, но я просто не вижу никаких данных, затронутых в моем файле базы данных main.db
SQLite.
Что я делаю не так?