c#update database无法正常工作

时间:2017-11-22 02:19:19

标签: c# database ado.net

所以我搜索了网络以找到解决方案,我发现当我们在visual studio中执行F5时,它实际上将原始数据库复制到一个新数据库中并使用代码中的副本以便更改您'已经制作不会在那里,他们告诉我将数据库属性设置为“如果更新则复制”并且它不起作用,我没有收到任何错误消息,但原始版本没有更新。

我做了一个测试,看看这段代码是否至少更新了副本,它是...... 在我看到数据库后运行我的应用程序时,更改不存在 所以我想更新原始数据库我该怎么做?

      private void button3_Click(object sender, EventArgs e)
    {
        string connectionString = ConfigurationManager.ConnectionStrings["NembManagement.Properties.Settings.NembDatabaseConnectionString"].ConnectionString;
        using (connection = new SqlConnection(connectionString))
        using (SqlCommand command = new SqlCommand("UPDATE Alunos SET Nome = @a WHERE Id=1", connection))
        {
            DataTable AlunosInfo = new DataTable();
            connection.Open();
            command.Prepare();
            command.Parameters.Clear();
            command.Parameters.AddWithValue("@a","aff");
            command.ExecuteNonQuery();
            //test to see if it was updating the copy and it is
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Alunos WHERE Alunos.Id=1 ", connection);
            adapter.Fill(AlunosInfo);


        }
    }

1 个答案:

答案 0 :(得分:0)

我以某种方式找到了解决方案,我将我的数据库属性Copy更改为nevercopy并且我得到另一个错误,说连接无法打开所以我通过更正应用程序配置中的连接字符串解决了这个问题

相关问题