vb.net中的数据库(INSERT) [英] database in vb.net(INSERT)

查看:188
本文介绍了vb.net中的数据库(INSERT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim userName As String = "user1"
 Dim sqlQuery2 As String = "INSERT INTO '" & userName & "' (Item,Qty,Price,Total,TimeString,DateString)



会发生这种情况吗?


can this be happen?

推荐答案

是的。

事实上它不会做任何有用的事情SQL可能会抱怨如果你试图使用它,因为你没有提供任何值 - 但作为字符串连接,它没关系。当然你提供了一个名为user1的表 - 我希望你没有!:笑:

您要查找的基本代码是:

Yes.
It won't do anything useful, in fact SQL will probably complain if you try to use it because you haven't provided any values - but as string concatenation, it's fine. Provided of course you have a table called "user1" - and I hope you haven't! :laugh:
The basic code you are looking for is:
Using con As New SqlConnection(strConnect)
    con.Open()
    Using com As New SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con)
        com.Parameters.AddWithValue("@C1", myValueForColumn1)
        com.Parameters.AddWithValue("@C2", myValueForColumn2)
        com.ExecuteNonQuery()
    End Using
End Using


要插入新行,你必须告诉sql什么是表和列你正在添加数据。然后,按相同的顺序,您必须列出值。一个sql insert语句看起来与此类似。

To insert a new row, you have to tell sql what table and columns you are adding data to. then, in the same order, you must list the values. An sql insert statement will look simmilar to this on.
INSERT INTO [Table1] (Column1,column2,column4) VALUES (1,'MickeyMouse',DECMBER/08/1986)


这篇关于vb.net中的数据库(INSERT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆