|
-
Jun 2nd, 2008, 01:53 AM
#1
Thread Starter
Junior Member
string "
hi
i make a code to read string from txt file and store it in string i call it (totsun). i want to insert values in a table withe two columes (oracle database) and the string totsun i want it to consider as the table name. the values to be inseert is y and ttime.
i want to write it as
strSQL = "insert into totsun values('y','stime')"
but i can't write " as a string
here my code
Open "C:\s1.txt" For Input As #2
Print ""
linecount = 1
Do While Not EOF(2)
string1 = "insert into "
string2 = "values('" & Chr(34) & " y " & Chr(34) & "','" & Chr(34) & " stime" & Chr(34) & "')"
Line Input #2, totsun
linecount = linecount + 1
Loop
Close #2
On Error GoTo ErrMsg
y = y & " , "
ttime = Format(Now, "HHMMss")
strSQL = Chr(34) & string1 & totsun & string2
could you plz check it and help me
i try to writ " as Chr(34)
-
Jun 2nd, 2008, 02:06 AM
#2
Re: string "
Code:
MsgBox """"
'Result: "
MsgBox """A"""
'Result: "A"
MsgBox """ A """
'Result: " A "
MsgBox "A""A"
'Result: A"A
MsgBox """"""
'Result: ""
So using dual quotes within quotes you can generate one quote character.
-
Jun 2nd, 2008, 02:17 AM
#3
Thread Starter
Junior Member
Re: string "
thank you 
but is the way what i try ro insert the table is corect ??
-
Jun 2nd, 2008, 02:26 AM
#4
Re: string "
Some comments:
Code:
Open "C:\s1.txt" For Input As #2
Print ""
linecount = 1
Do While Not EOF(2)
' why these two are assigned on every time a line from file is read?
' neither changes as reading the file progresses
string1 = "insert into "
string2 = "values('" & Chr(34) & " y " & Chr(34) & "','" & Chr(34) & " stime" & Chr(34) & "')"
Line Input #2, totsun
linecount = linecount + 1
Loop
Close #2
On Error GoTo ErrMsg
' I don't know what these two are for, they don't affect the last code line here
y = y & " , "
ttime = Format(Now, "HHMMss")
' Chr(34) is too much here, totsun would be the last line read from the file
' use MsgBox totsun to see contents to ensure it isn't an empty line
strSQL = Chr(34) & string1 & totsun & string2
-
Jun 2nd, 2008, 02:36 AM
#5
Thread Starter
Junior Member
Re: string "
i make it like this write now
strSQL = """ insrt into" & totsun & "values('y','stime')"""
...........................................
abut the reading from the file what is your suggestion and what is the best way to read onle the string in the file
howi fix that
plz help
Last edited by conan911; Jun 2nd, 2008 at 02:48 AM.
-
Jun 2nd, 2008, 04:31 AM
#6
Re: string "
Thread moved to Database Development forum - which is where SQL questions belong
i make it like this write now
strSQL = """ insrt into" & totsun & "values('y','stime')"""
That is not a valid SQL statement... I don't see what you are trying to do, as what you posted originally (strSQL = "insert into totsun values('y','stime')") is much more correct.
If you want to replace y and stime with values from the text file, see the article How can I put the value of a variable/control into my SQL statement? from the "SQL" section of our Database Development FAQs/Tutorials (at the top of this forum)
-
Jun 2nd, 2008, 05:47 AM
#7
Re: string "
I think totsun is a variable name rather than a table name. He's reading the tablename from a file and putting it into the totsun variable which he then wants to use when building the sql string.
Conan, you've come awfully close to solving this yourself. I think what you're after is this:-
While Not EOF(2)
Line Input #2, totsun
string1 = "insert into " & totsun & _
string2 = " values('y','stime')"
linecount = linecount + 1
wend
...although I'm curious as to whether you really mean that you want to insert y and stime into the tables. At the moment they're literals, do you actually want them to be variables?
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
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
|