Re: insert on a specific row
I have done an INSERT/SELECT but never the other way around.
Why not just run a SELECT, then run a separate INSERT?
Re: insert on a specific row
Thanks H
Once I do the select * from table where Doc=" varaible"
how do I do the insert in that particular row
Sorry for the stupid question but low on knowledge on sql and new to VB as can tell
Thanks for battling with me
Re: insert on a specific row
Assumptions: You are using ADO code to connect to your database
In this example adoRS is my recordset object and ADOCn is my connection object. Both have been previously declared as project wide Public or form level Private
Code:
Dim sSQL As String
Dim strMyVariable As String
sSQL = SELECT field1, field2, field3 FROM tablename WHERE Doc = '" & variablename & "' "
Set adoRS = New ADODB.Recordset
adoRS.Open sSQL, ADOCn
strMyVariable = adoRS.Fields.Item("field1").Value
adoRS.Close
Set adoRS = Nothing
sSQL = "UPDATE tablename SET field1 = '" & strMyVariable & "' "
sSQL = sSQL & "WHERE Doc = '" & variablename & "' "
ADOCn.Execute sSQL
Re: insert on a specific row
Thanks again H
I am using Sqlconnection
can I do something like this, still does not work
stringcommand1 = "INSERT INTO Table1 (Doc,Number)values ('" & "yes" & "','" & Number & "') select docnum from Table1 WHERE docNum=" & DocNumber & ""
tthis is killing me, thanks again H
Re: insert on a specific row
That is the kind that I've used; i.e. INSERT/SELECT - that should work. Give it a try and post the results.
Re: insert on a specific row
Thanks H for battling I know is time consuming for you, I really app.
the error I get is the following
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
Nothing else
Re: insert on a specific row
Is "yes" are variable or a literal?
Re: insert on a specific row
Re: insert on a specific row
Quote:
Originally Posted by GUARO
its hard code
That means it is a literal. :)
Then do
Code:
values ('yes'," & "','" & Number & "')
Re: insert on a specific row
H
I had it working, the problem was that for some reason the field I was reading from the txt file came already as "xxxxx" the when on the sql statement looked like ""xxxxx"" and it could not find it but once I strip it it inserted the value find BUT in a new line not on the same record
the new value was inserted on a new line and did not filled up the line where the doc number was
can you help me on this
Thanks again
Re: insert on a specific row
H
I think I have to set value as what I am trying to do is change a value that is already there fro something else? from null to yes and from null to text
what do you think and if that is the case how do I do go doing that
Re: insert on a specific row
H
Can you fix this sql statement please
stringcommand1 = "UPDATE recon SET (CheckNum,Docpaid)VALUES ('" & checkNumber & "', '" & yes & "') WHERE DocNum=" & DocNumber & ""
Re: insert on a specific row
Wha tis the backend DB? What is the datatype for the field Docpaid?
Re: insert on a specific row
Again, "yes" is a hard code literal so it should not be encapsulated in double quotes....for literal hard codes (that are text) use just single quotes.
Re: insert on a specific row
H
my db is sql 2000 and thanks to you I got the problem solved.
Update does not allow () the have to be field=value,field=value and so on, so that part is already fixed.- thanks a bunch for battling with me all this time, I really appreciate.
This is what I call go the extra mile to help.
Thanks again