Groups | Blog | Home
all groups > asp.net > march 2007 >

asp.net : VB.NET and SQLDataSource


Dave
3/23/2007 10:24:29 PM
Let's say that you wanted to perform an INSERT, but that one of the
values in the insert had to be selected from another table based on
the text property of a TextBox? Something like this:

insert into visit_table (date, id) values (@DATE, (select top 1 id
from id_table where name = NameBox.Text))

What would the InsertCommand for a SQLDataSource look like in VB.NET
to do this? I have beat my head on it for hours with no luck.

Dave
Alexey Smirnov
3/24/2007 6:45:49 AM
[quoted text, click to view]


insert into visit_table (date, id)
select top 1 @DATE, id
from id_table where name = ...
Cowboy (Gregory A. Beamer)
3/24/2007 9:07:48 AM
INSERT INTO visit_table
SELECT Top 1 @Date, id
FROM id_table WHERE name = @NameBoxText

That is the SQL Server side. You will have to supply the values for @Date
and @NameBoxText. You have a choice to do this as a stored procedure or
inline SQL.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
[quoted text, click to view]
DaveC
3/24/2007 9:15:05 PM

That was the ticket! It worked perfect!

Thanks Cowboy!!

Dave
AddThis Social Bookmark Button