|
-
Dec 12th, 2002, 11:22 AM
#1
Thread Starter
Addicted Member
String Help
Hello.
Im creating an interface like MS Access to create MySQL tables, it is almost done, BUT i have a "small" problem with a string concat, here is the code.
Code:
strSQL = "CREATE TABLE " & txtTableName & " ( "
For dimintRow = 1 To 19
For dimintCol = 1 To 2
TempStr = fgMySQLAccess.TextMatrix(dimintRow, dimintCol)
strSQL = strSQL & " " & TempStr
DoEvents
Next dimintCol
If TempStr <> "" Then
strSQL = strSQL & " , "
End If
Next dimintRow
strSQL = strSQL & " )"
txtSQLQuery = strSQL
I need to separate the table fields with a comma (","), but the way im doing it i always get an undesired come at the end of the sql
Code:
CREATE TABLE MyTable ( OneField Text , AnotherField Text , EvenAnotherField Text , )
Is there a way to get rid of it?
Thanks in advance!
-
Dec 12th, 2002, 11:38 AM
#2
Frenzied Member
If you add the first field to the string before the loop and then add the commas before the fields in the loop, you will not have any extra commas.
-
Dec 12th, 2002, 11:39 AM
#3
Addicted Member
Something like this outside the loop structure:
txtsqlstr = Left(strsql, Len(Trim(strsql)) - 1) & ")"
JS
Disclaimer:
* The preceding message was in no means meant to be critical, mean spirited, insincere, or facetious.
Disclaimer for disclaimer:
The preceding disclaimer may in fact be facetious in nature.
Thanks,
Jim
-
Dec 12th, 2002, 11:39 AM
#4
Hyperactive Member
Code:
strSQL = "CREATE TABLE " & txtTableName & " ( "
For dimintRow = 1 To 19
For dimintCol = 1 To 2
TempStr = fgMySQLAccess.TextMatrix(dimintRow, dimintCol)
strSQL = strSQL & " " & TempStr
DoEvents
Next dimintCol
If TempStr <> "" Then
strSQL = strSQL & " , "
End If
Next dimintRow
strSQL = left(strSQL, len(strSQL) - 2)
strSQL = strSQL & " )"
txtSQLQuery = strSQL
Should fix it
-
Dec 12th, 2002, 11:40 AM
#5
Re: String Help
this will remove the last character from your string.. do this before you execute the SQL statement
VB Code:
strSQL = left(strSQL,len(strSQL) - 2)
-
Dec 12th, 2002, 11:41 AM
#6
That's easy,
you put a comma after each strSQL (if its not empty).
So also do this for the last one, which you don't want to have. One way to get rid of it is to remove the last three characters of the strSQL just before you put the ")" at the end.
VB Code:
strSQL=right(strSQL,len(strSQL-3))
It's 3 char'S because you add " , ", which are 3 char's.
There are other ways to do it, but.....
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Dec 12th, 2002, 11:45 AM
#7
Kleinma he added " , " not only " ," !
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Dec 12th, 2002, 11:54 AM
#8
Originally posted by opus
Kleinma he added " , " not only " ," !
well i think that they would get the idea.. you are correct however
even though it should work with 1 space in there anyway
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|