C# SQL INSERT 未出现在数据库表 "no errors or exceptions thrown"中

标签 c# sql-server database

我一直在努力弄清楚为什么我的插入没有出现在我的数据库表中。我已经完成了很多次,我没有看到错误,也没有异常(exception)。我是使用数据库的新手,所以也许我能看到一些东西,我们将不胜感激。谢谢

using(SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].[EmployeeInfo] 
(Id, name, password) VALUES (@Id, @name, @password)", connection)) {
     cmd.CommandType = CommandType.Text;
     cmd.Parameters.AddWithValue("@Id", Id++);
     cmd.Parameters.AddWithValue("@name", name);
     cmd.Parameters.AddWithValue("@password", password);

     try {
       connection.Open();
       //rows effected
       int i = cmd.ExecuteNonQuery();

       MessageBox.Show("User saved");

     } catch (SqlException ex) {
       MessageBox.Show(ex.Message, ex.GetType().ToString());

     } finally {
       nameBox.Clear();
       passwordBox.Clear();
       connection.Close();
     }
}

这是来自配置文件的连接字符串

<connectionStrings> 
   <add name="SBPA.Properties.Settings.EmployeeLoginConnectionString" 
        connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\EmployeeLogin.mdf;Integrated Security=True" 
        providerName="System.Data.SqlClient" /> 
</connectionStrings>

最佳答案

Hay 伙计们,感谢大家的回复,几个小时后我终于发现我的代码没有任何问题。正在更新的数据库是 bin/debug 文件夹中的数据库,而不是我在解决方案中引用的数据库。我没有意识到在处理项目时所做的所有更改都是针对调试文件夹中的副本完成的。

关于C# SQL INSERT 未出现在数据库表 "no errors or exceptions thrown"中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27141285/

相关文章:

c# - 使用 C# 的 AES 加密

sql-server - SQL 触发器(更改事件)到 Azure 函数

php - 基本的PHP程序不过滤表

javascript - 无法使用sequelize和mysql根据包含的模型属性过滤数据

mysql - 哪一种是为单个字段存储多个值的最佳方式?逗号分隔或分隔表

c# - 什么是 "private .NET framework"?

c# - 我可以让 Moq 为模拟类添加属性吗?

sql - 查找用于将财政季度结果与上一年进行比较的查询

c# - 如何确保只有 *.exe 或 *.dll 文件进入输出文件夹,而任何其他构建文件进入中间文件夹 VS2012?

sql - 使用随机字段更新表