To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Database Development

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Apr 24th, 2007, 11:08 AM   #1
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
insert on a specific row

Hi gurus.

Need your help.

I have a sql server table with a few fields already populated, I have a text file that I need to read , the txt file has a field named Doc, I need to read the line whic I have no problem and find the same doc on the sql table and add something to a field on the same row.

How can I accomplish this is sql.- Is there such a thing as select- where and then insert on the same statement.

Thanks a bunch Gurus.
GUARO is offline   Reply With Quote
Old Apr 24th, 2007, 11:11 AM   #2
Hack
Super Moderator
 
Hack's Avatar
 
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 52,309
Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)
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?
__________________
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum.

Creating A Wizard In VB.NET
Modifications Required For VB6 Apps To Work On Vista
Paging A Recordset
What is wrong with using On Error Resume Next
IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects!
Microsoft MVP 2005/2006/2007/2008/2009
Hack is offline   Reply With Quote
Old Apr 24th, 2007, 11:18 AM   #3
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
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
GUARO is offline   Reply With Quote
Old Apr 24th, 2007, 11:52 AM   #4
Hack
Super Moderator
 
Hack's Avatar
 
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 52,309
Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)
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
__________________
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum.

Creating A Wizard In VB.NET
Modifications Required For VB6 Apps To Work On Vista
Paging A Recordset
What is wrong with using On Error Resume Next
IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects!
Microsoft MVP 2005/2006/2007/2008/2009
Hack is offline   Reply With Quote
Old Apr 24th, 2007, 12:02 PM   #5
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
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
GUARO is offline   Reply With Quote
Old Apr 24th, 2007, 12:22 PM   #6
Hack
Super Moderator
 
Hack's Avatar
 
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 52,309
Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)
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.
__________________
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum.

Creating A Wizard In VB.NET
Modifications Required For VB6 Apps To Work On Vista
Paging A Recordset
What is wrong with using On Error Resume Next
IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects!
Microsoft MVP 2005/2006/2007/2008/2009
Hack is offline   Reply With Quote
Old Apr 24th, 2007, 12:26 PM   #7
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
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
GUARO is offline   Reply With Quote
Old Apr 24th, 2007, 12:30 PM   #8
Hack
Super Moderator
 
Hack's Avatar
 
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 52,309
Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)
Re: insert on a specific row

Is "yes" are variable or a literal?
__________________
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum.

Creating A Wizard In VB.NET
Modifications Required For VB6 Apps To Work On Vista
Paging A Recordset
What is wrong with using On Error Resume Next
IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects!
Microsoft MVP 2005/2006/2007/2008/2009
Hack is offline   Reply With Quote
Old Apr 24th, 2007, 12:33 PM   #9
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
Re: insert on a specific row

its hard code
GUARO is offline   Reply With Quote
Old Apr 24th, 2007, 12:35 PM   #10
Hack
Super Moderator
 
Hack's Avatar
 
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 52,309
Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)
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 & "')
__________________
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum.

Creating A Wizard In VB.NET
Modifications Required For VB6 Apps To Work On Vista
Paging A Recordset
What is wrong with using On Error Resume Next
IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects!
Microsoft MVP 2005/2006/2007/2008/2009
Hack is offline   Reply With Quote
Old Apr 24th, 2007, 12:50 PM   #11
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
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
GUARO is offline   Reply With Quote
Old Apr 24th, 2007, 12:55 PM   #12
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
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
GUARO is offline   Reply With Quote
Old Apr 24th, 2007, 01:10 PM   #13
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
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 & ""
GUARO is offline   Reply With Quote
Old Apr 24th, 2007, 01:28 PM   #14
GaryMazzone
Back to the Yanks I guess
 
GaryMazzone's Avatar
 
Join Date: Aug 05
Location: Dover,NH
Posts: 4,551
GaryMazzone is a glorious beacon of light (400+)GaryMazzone is a glorious beacon of light (400+)GaryMazzone is a glorious beacon of light (400+)GaryMazzone is a glorious beacon of light (400+)GaryMazzone is a glorious beacon of light (400+)GaryMazzone is a glorious beacon of light (400+)
Re: insert on a specific row

Wha tis the backend DB? What is the datatype for the field Docpaid?
__________________
Sometimes the Programmer
Sometimes the DBA

Mazz1
GaryMazzone is offline   Reply With Quote
Old Apr 24th, 2007, 01:32 PM   #15
Hack
Super Moderator
 
Hack's Avatar
 
Join Date: Aug 01
Location: Sterling Heights, Michigan
Posts: 52,309
Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)Hack has much to be proud of (1500+)
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.
__________________
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum.

Creating A Wizard In VB.NET
Modifications Required For VB6 Apps To Work On Vista
Paging A Recordset
What is wrong with using On Error Resume Next
IT professionals freelancer site. Register today to find coders, or offer your services for available freelance projects!
Microsoft MVP 2005/2006/2007/2008/2009
Hack is offline   Reply With Quote
Old Apr 24th, 2007, 05:08 PM   #16
GUARO
Lively Member
 
Join Date: Mar 01
Posts: 92
GUARO is an unknown quantity at this point (<10)
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
GUARO is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Database Development


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:20 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.