开发者

vb.net handling many table name using string

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 开发者_Python百科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


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.


Or

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

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


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜