Tough SQL Query.

  • Thread starter Thread starter Arial
  • Start date Start date
A

Arial

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.
 
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 line
cmdstr.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'"
 
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 own
line.
You could also do a .replace on the string.




.
 
Hi Herfried,

It was a VB question, lol.

t1 = "TableName"
cmdstr = "Blah blah t1 blah blah"

Q: Why is cmdstr wrong?
A: Oops. I havn't learnt how to concatenate strings!!

Btw, it's the weekend again - go and have some fun. :-)

No, I mean some <different> fun! ;-D

Regards,
Fergus
 
You should be using & instead of +, I hope.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
 
Hello,

Fergus Cooney said:
It was a VB question, lol.

t1 = "TableName"
cmdstr = "Blah blah t1 blah blah"

Q: Why is cmdstr wrong?
A: Oops. I havn't learnt how to concatenate strings!!

Btw, it's the weekend again - go and have some fun. :-)

No, I mean some <different> fun! ;-D

Today (yesterday) I was on "Mac Styria Tour" with some friends. We visited
all 20 McDonals's restaurants in our district (Styria).

;-)))
 
Hi Herfried,

My apologies, I thought I'd already talked about it here, but I did a search and nothing came up. Now I remember it was in a
totally different forum!!

As I mentioned, I don't know German, but love the sound of it. So sometimes in my pretend German I make up words using an
English root and German prefixes and suffixes.

Wenn Sie "gebloaten" sind, es ist nicht <voll> und es ist nicht <sehr voll>. Nein, es ist "ooooooh, Ich habe viel zu viel
gegessen." voll. :-)

From the English "bloated" - which I imagine after 20 Big Macs, you would have been, lol.


From another (unsent) reply:
|| > No, I mean some <different> fun! ;-D
||
|| We visited all 20 McDonalds's restaurants

That's certainly different. :-)

What was the purpose? Did you eat at each one, like in a pub crawl?

Regards,
Fergus
 
And this has relevance to a 'Tough SQl Query'?

Fergus Cooney said:
Hi Herfried,

My apologies, I thought I'd already talked about it here, but I did a
search and nothing came up. Now I remember it was in a
totally different forum!!

As I mentioned, I don't know German, but love the sound of it. So
sometimes in my pretend German I make up words using an
English root and German prefixes and suffixes.

Wenn Sie "gebloaten" sind, es ist nicht <voll> und es ist nicht <sehr
voll>. Nein, es ist "ooooooh, Ich habe viel zu viel
 
Seeing as this is a newsgroup about the VB.Net language and the thread is
about 'Tough SQL Query' then Yes.
 
|| Seeing as this is a newsgroup about the
|| VB.Net language and the thread is
|| about 'Tough SQL Query'

Insufficient reason.
 
Stephany,
Yes this is a newsgroup about a language,
And the people who often contribute in this newsgroup, did add somethimes
extra to this newsgroup.
This gives a better idea why they are writting something in a certain way
and that makes the discussion richer and better understandable for the ones
who contributes a lot.

You can see that too in the discussion about for next and do while.
A Spanish writter tells to an Austrian writter that he should not use those
difficult Englisch words.
After some chat they understand each other.

Herfried, was quick answering messages yesterday.
Now we know he was bloated and could not reach his keyboard with his arms.

Cor
 
Stephany Young said:
And this has relevance to a 'Tough SQl Query'?

They love this kind of discussions. It has it's advantages: After receiving
100 new posts, you can mark 90 of them as "read". ;-))))
 
Hello,

Fergus Cooney said:
As I mentioned, I don't know German,

You know a lot of German...
but love the sound of it. So sometimes in my pretend German
I make up words using an English root and German prefixes and
suffixes.
:-)

Wenn Sie "gebloaten" sind, es ist nicht <voll> und es ist nicht
<sehr voll>. Nein, es ist "ooooooh, Ich habe viel zu viel
gegessen." voll. :-)

Now I understand what you mean.
From the English "bloated" - which I imagine after 20 Big Macs, you
would have been, lol.

I didn't eat 20 Big Macs.
From another (unsent) reply:
|| > No, I mean some <different> fun! ;-D
||
|| We visited all 20 McDonalds's restaurants

That's certainly different. :-)

What was the purpose? Did you eat at each one, like in a pub
crawl?

Yes. It doesn't make sense at all, but I meet some good friends.
 
Back
Top