473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VB.NET and SQLDataSource

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

Mar 24 '07 #1
3 1557
On Mar 24, 6:24 am, "Dave" <davec...@gmail.comwrote:
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

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

Mar 24 '07 #2
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!
*********************************************
"Dave" <da******@gmail.comwrote in message
news:11**********************@p15g2000hsd.googlegr oups.com...
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
Mar 24 '07 #3

That was the ticket! It worked perfect!

Thanks Cowboy!!

Dave

Mar 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
3
by: zapov | last post by:
Hi! Did anyone successfully managed to use some custom ADO.NET provider with SqlDataSource? I'd like to connect to some other database than MSSQL (like MySQL, Firebird or PostgreSQL) but I'm...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
2
by: djc | last post by:
1) I am wondering if I should be using an sqlDataSource object for my particular scenario. I need to loop through a listbox and perform an INSERT sql operation for each item. Could be a few or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.