vb.net 使用字符串处理许多表名

发布于 2024-09-28 22:51:34 字数 246 浏览 3 评论 0原文

我将表名存储在字符串

ugad = "INSERT INTO tb(Ugname,Ugdob,Uggender)"

中,这是功能良好的普通查询。

但我需要将表名存储在名为“dept”的字符串中,

并且该字符串将在不同时间具有差异表名称。我应该如何运行它,我应该给出Wat查询。

ugad =“插入部门(Ugname,Ugdob,Uggender)” 我知道这个查询是无效的。我可以知道正确的查询吗

Am storing a table name in a String

ugad = "INSERT INTO tb(Ugname,Ugdob,Uggender)"

this is the ordinary query which functions well.

But i need to store a Tablename in a string called "dept"

and this string will have diff table name at diff times. How should i run it, Wat query should I Give.

ugad = "INSERT INTO dept(Ugname,Ugdob,Uggender)"
I know this query is not vaild. May i know the correct query

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魂归处 2024-10-05 22:51:34

使用:

ugad = "INSERT INTO " & dept & "(Ugname,Ugdob,Uggender)" 

注意,可以说有比上述方法更安全、更好的方法来编写 SQL(如果您担心通过 SQL 注入恶意或意外干扰您的基础数据),但希望这可以帮助您入门。

Use:

ugad = "INSERT INTO " & dept & "(Ugname,Ugdob,Uggender)" 

N.B. There are arguably safer, better ways to compose SQL (if you are worried about malicious or accidental interference with your underlying data through SQL injection) than the above but hopefully that gets you started.

方圜几里 2024-10-05 22:51:34

或者

ugad = String.Format("INSERT INTO {0}(Ugname,Ugdob,Uggender)", dept)

我认为哪个更容易阅读并且更容易维护。

Or

ugad = String.Format("INSERT INTO {0}(Ugname,Ugdob,Uggender)", dept)

Which I think is easier to read and easier to maintain.

许你一世情深 2024-10-05 22:51:34

如果我理解正确的话,你需要尝试类似

ugad = "INSERT INTO " + dept + "(Ugname,Ugdob,Uggender)"

Have a llok at Operators in VB.NET

请记住,一旦开始循环连接,字符串连接可能会非常慢,因此请始终牢记 StringBuilder 类 存在,并且比普通连接快很多...

If I understand you correctly you neet to try something like

ugad = "INSERT INTO " + dept + "(Ugname,Ugdob,Uggender)"

Have a llok at Operators in VB.NET

Just remember that string concatenation can be very slow once you start concatenating in loops, so always have in the back of your mind that the StringBuilder Class exists, and is a lot faster than normal concatenation...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文