我正在使用 Dapper 将我的代码连接到我的 LocalDB。我有很多其他函数可以完美地访问信息,可以读取它并将其带入我的程序,但由于某种原因,我将信息插入数据库的函数没有做任何事情。我已经确认没有抛出异常,并且在单击按钮时到达代码(如消息框所示),但没有任何数据保存到数据库中。我还检查了我的查询,当我直接查询数据库时它工作正常,只是当我出于某种原因让代码执行它时(因此是我的问题)。出了什么问题?
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Configuration;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ProjectManager
{
class Database
{
// Connection Variables
private IDbConnection connection = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Database"].ConnectionString);
// Get Number of Projects
public int GetNumOfProjects()
{
return connection.Query<int>("select count(*) from Projects").FirstOrDefault();
}
// Load Projects
public ProjectPane LoadProjects(int i, Point start)
{
// Variables
string title;
string subject;
int progress;
// Load ProjectPane with Information
title …Run Code Online (Sandbox Code Playgroud)