vb.net 标签“N”已经声明。标签名称在查询批处理或存储过程中必须是唯一的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43362571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The label 'N' has already been declared. Label names must be unique within a query batch or stored procedure
提问by Klaas-Jelle Ras
I have a question.
我有个问题。
I need to make a program in vb.net that needs to set text in a sql database. But everytime when I click on Export to Database the program shuts down and says:
我需要在 vb.net 中制作一个需要在 sql 数据库中设置文本的程序。但是每次当我单击“导出到数据库”时,程序都会关闭并说:
The label 'N' has already been declared. Label names must be unique within a query batch or stored procedure
标签“N”已经声明。标签名称在查询批处理或存储过程中必须是唯一的
I don't know what this means, I'm new to .net languages. Hope someone can help me.
我不知道这意味着什么,我是 .net 语言的新手。希望可以有人帮帮我。
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\klaasjelle\documents\visual studio 2017\Projects\Opdracht\Opdracht\Opdracht1.mdf;Integrated Security=True"
con.Open()
cmd.Connection = con
cmd.CommandText = $"INSERT INTO opdracht ('FilePath', 'ImageSide', 'ImageSize') VALUES ('{TextBox1.Text}')"
cmd.ExecuteNonQuery()
End Sub
采纳答案by Whencesoever
You have not valid Command text there i suppose.
我想你那里没有有效的命令文本。
cmd.CommandText = "INSERT INTO opdracht (FilePath, ImageSide, ImageSize) VALUES ('"
+ TextBox1.Text + "')"

