Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT and SELECT in VB.NET 2

Status
Not open for further replies.

NMickey

Programmer
Nov 7, 2004
15
US
Hi,

I want to to select an item from my table and hold (insert) it into a string that I declare. How do I do it in VB.NET.

For instance,

Dim holdItem as string

Dim SQL as string = "SELECT item from mytable WHERE ...."
My question is how select that item and insert into holdItem as I declare above in ADO.NET or VB.NET? Any help would appreciate it.

Thx
 
Mickey

You either build up a dynamic where clause for your SQL statement...
Code:
holditem=" id = 1'
Dim SQL as string = "SELECT item from mytable WHERE " + holditem

or assuming you have already got the items in an earlier selected dataset. You can use the .select command of the datatable
Code:
'ds is your dataset
dim rows as datarow() = ds.tables(0).select("id=1")




Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
Darn squeak, you should be teaching them how to use parameters. ;-)
Lets asume that your command is called comtemp.

Code:
comtemp.parameters.add("@id",sqldbtype.int)
comtemp.parameters(0).value = 1
comtemp.commandtext = "SELECT item from mytable WHERE id = @id"

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top