艰难的SQL查询。 [英] Tough SQL Query.
问题描述
我的SQL字符串很奇怪。
在我的应用程序中,我需要从
未知名称表中选择一些东西。但是在执行
SQL命令之前我知道了表名。
例如,
Dim varname as string =' '我的变量之一。这是表名的
的一部分。
Dim t1 as String = varname +" 0000"
Dim cmdstr as string ="从t1选择名称,地址
名称=?"
cmdstr.parameters.add(" Name",odbctype(char),50 )
我使用字符串concaticate方法并出错。
找不到表t1。
有人可以告诉我该怎么做吗?
试试这个:
>
Dim t1 as String = varname +" 0000"
Dim cmdstr as string =" Select Name,Addr from + t1 +其中Name =?"
cmdstr.parameters.add(" Name",odbctype(char),50)
我还是新的在.NET语法中,所以concats可能必须在他们自己的
行中出现。
你也可以在字符串上做一个.replace。
" Arial" <氩******** @ yahoo.com>在消息中写道
news:2b **************************** @ phx.gbl ... < blockquote class =post_quotes>我的SQL字符串有点奇怪。
在我的应用程序中,我需要从
未知名称表中选择一些东西。但是我知道在执行
SQL命令之前的表名。
例如,
Dim varname as string =''我的变量之一。它是表名的一部分。
Dim t1 as String = varname +" 0000"
Dim cmdstr as string =" Select name,Addr from t1 where
名称=?"
cmdstr.parameters.add(" Name",odbctype(char),50)
我使用字符串concaticate方法和得到错误。
找不到表t1。
有人可以告诉我怎么做吗?
< blockquote>使用&连接字符串的运算符:
Dim t1 As String = strVarName& " 0000"
Dim cmdstrAs String =" SELECT Name,Addr FROM" &安培; t1& " WHERE Name =?"
此外,这行
cmdstr.parameters.add(" Name",odbctype(char),50)
吗?
String对象没有这样的属性/方法。
-
HTH,
- Tom Spink,überGeek
请回复新闻组,
所以所有人都可以受益>
也许它是一款名为''惩罚用户''的游戏,
Richard Brown" < RB **** @ easylift.org>在消息中写道
新闻:eF ************** @ TK2MSFTNGP10.phx.gbl ...试试这个:
Dim t1 as String = varname +" 0000"
Dim cmdstr as string =" Select Name,Addr from + t1 +其中Name =?"
cmdstr.parameters.add(" Name",odbctype(char),50)
我仍然是.NET语法的新手,所以concats可能必须在他们的
自己的行中发生。
你也可以在字符串上做一个.replace。
Arial <氩******** @ yahoo.com>在消息中写道
新闻:2b **************************** @ phx.gbl ...我的SQL字符串很奇怪。
在我的应用程序中,我需要从一个未知的名称表中选择一些东西。但是我知道在执行
SQL命令之前的表名。
例如,
Dim varname as string =''我的变量之一。它是表名的一部分。
Dim t1 as String = varname +" 0000"
Dim cmdstr as string =" Select name,Addr from t1 where
名称=?"
cmdstr.parameters.add(" Name",odbctype(char),50)
我使用字符串concaticate方法和得到错误。
找不到表t1。
有人可以告诉我该怎么做吗?
谢谢!它很棒!
我欠你一个!
-----原帖-----
试试这个:
Dim t1 as String = varname +" 0000"
Dim cmdstr as string =" Select Name,Addr from + t1
+"其中Name =?" cmdstr.parameters.add(" Name",odbctype(char),50)
我仍然是.NET语法的新手,所以concats可能需要
ownline。
你也可以在字符串上做一个.replace。
Arial <氩******** @ yahoo.com>在消息中写道
新闻:2b **************************** @ phx.gbl ...我的SQL字符串很奇怪。
在我的应用程序中,我需要从一个未知的名称表中选择一些东西。但是我知道在执行SQL命令
之前的表名。
例如,
Dim varname as string =''我的变量之一。这是表名的
部分。
Dim t1 as String = varname +" 0000"
Dim cmdstr as string =" Select name,Addr from t1 where
名称=?"
cmdstr.parameters.add(" Name",odbctype(char),50)
我使用字符串concaticate方法和得到错误。
找不到表t1。
有人可以告诉我该怎么做吗?
。
My SQL string is kind of wierd one.
In my application, I need to select things from an
unknown name table. But I know the table name before the
SQL command is executed.
For instance,
Dim varname as string = ''one of my variable. It''s part of
the table name.
Dim t1 as String = varname+ "0000"
Dim cmdstr as string ="Select Name, Addr from t1 where
Name = ?"
cmdstr.parameters.add("Name", odbctype(char), 50)
I use a string concaticate method and got error.
"Cannot find table t1".
Can some one tell me how to do that ?
Try this:
Dim t1 as String = varname+ "0000"
Dim cmdstr as string ="Select Name, Addr from " + t1 + " where Name = ?"
cmdstr.parameters.add("Name", odbctype(char), 50)
I''m still new at .NET syntax, so the concats may have to occur in their own
line.
You could also do a .replace on the string.
"Arial" <Ar********@yahoo.com> wrote in message
news:2b****************************@phx.gbl...My SQL string is kind of wierd one.
In my application, I need to select things from an
unknown name table. But I know the table name before the
SQL command is executed.
For instance,
Dim varname as string = ''one of my variable. It''s part of
the table name.
Dim t1 as String = varname+ "0000"
Dim cmdstr as string ="Select Name, Addr from t1 where
Name = ?"
cmdstr.parameters.add("Name", odbctype(char), 50)
I use a string concaticate method and got error.
"Cannot find table t1".
Can some one tell me how to do that ?
Use the & operator for concatenating strings:
Dim t1 As String = strVarName & "0000"
Dim cmdstrAs String = "SELECT Name, Addr FROM " & t1 & " WHERE Name = ?"
Also, what does this linecmdstr.parameters.add("Name", odbctype(char), 50) do?
The String object has no such property/method.
--
HTH,
-- Tom Spink, über Geek
Please respond to the newsgroup,
so all can benefit
"Maybe it''s a game called ''Punish the User''"
"Richard Brown" <rb****@easylift.org> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl... Try this:
Dim t1 as String = varname+ "0000"
Dim cmdstr as string ="Select Name, Addr from " + t1 + " where Name = ?"
cmdstr.parameters.add("Name", odbctype(char), 50)
I''m still new at .NET syntax, so the concats may have to occur in their own line.
You could also do a .replace on the string.
"Arial" <Ar********@yahoo.com> wrote in message
news:2b****************************@phx.gbl...My SQL string is kind of wierd one.
In my application, I need to select things from an
unknown name table. But I know the table name before the
SQL command is executed.
For instance,
Dim varname as string = ''one of my variable. It''s part of
the table name.
Dim t1 as String = varname+ "0000"
Dim cmdstr as string ="Select Name, Addr from t1 where
Name = ?"
cmdstr.parameters.add("Name", odbctype(char), 50)
I use a string concaticate method and got error.
"Cannot find table t1".
Can some one tell me how to do that ?
Thanks! it works great!
I owe you one!
-----Original Message-----
Try this:
Dim t1 as String = varname+ "0000"
Dim cmdstr as string ="Select Name, Addr from " + t1 + " where Name = ?" cmdstr.parameters.add("Name", odbctype(char), 50)
I''m still new at .NET syntax, so the concats may have to occur in their ownline.
You could also do a .replace on the string.
"Arial" <Ar********@yahoo.com> wrote in message
news:2b****************************@phx.gbl...My SQL string is kind of wierd one.
In my application, I need to select things from an
unknown name table. But I know the table name before the SQL command is executed.
For instance,
Dim varname as string = ''one of my variable. It''s part of the table name.
Dim t1 as String = varname+ "0000"
Dim cmdstr as string ="Select Name, Addr from t1 where
Name = ?"
cmdstr.parameters.add("Name", odbctype(char), 50)
I use a string concaticate method and got error.
"Cannot find table t1".
Can some one tell me how to do that ?
.
这篇关于艰难的SQL查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!