简体   繁体   English

VB.NET表适配器未在数据库中插入行

[英]VB.NET Table Adapter not inserting row in the database

I wrote this really simple query in the dataset designer: 我在数据集设计器中编写了这个非常简单的查询:

INSERT INTO tabela (Id, Nome)
VALUES (@Id, @Nome);  

SELECT Id, Nome 
FROM tabela 
WHERE (Id = @Id)

When I run this in the query builder, it inserts the data into the SQL database normally. 当我在查询生成器中运行此命令时,它会将数据正常插入SQL数据库中。

My problem is: I created a button on the form, and added this code to the button click event handler: 我的问题是:我在窗体上创建了一个按钮,并将此代码添加到了按钮单击事件处理程序中:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim ID As Integer
    Dim Nome As String

    ID = 1
    Nome = "teste"

    TabelaTableAdapter.NovoItem(ID, Nome)
End Sub

The problem is that when I click in the button, nothing happens in my database, no row is inserted. 问题是,当我单击按钮时,数据库中没有任何反应,没有行插入。

Where is the issue? 问题出在哪里?

I finally found the issue. 我终于找到了问题。 I found this comment in the internet that fixed my problem: 我在互联网上找到此评论,解决了我的问题:

his issue can be fixed by clicking on the database in the solution explorer and adjusting the property to read 'Copy if Newer' instead of 'Copy Always'. 可以通过在解决方案资源管理器中单击数据库并将属性调整为“如果较新则复制”而不是“始终复制”来解决此问题。 If you set it to 'Do Not Copy', you need to manually copy it or you an exception saying that it can't find the database file. 如果将其设置为“不复制”,则需要手动复制它,否则会出现异常提示它找不到数据库文件。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM