Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Extract variables from a database


Extract variables from a database

Reply
  #1 (permalink)  
Old 08-28-03, 05:48 AM
andreasberglind andreasberglind is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Sweden
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Extract variables from a database

I have a MS SQL database with som tables in it. what Iīd like to do is get an ID value from one of the tables to another table. I guess I should be able to do this with ASP.Net(C#), but I canīt get it there.

This is the SQL stmt:
select ActorID from Actor where ActorName = 'Name'

then I want the value of this, which is an int, into an int variable, such as:
int actor_ID;

how do i get that?
Reply With Quote
  #2 (permalink)  
Old 08-28-03, 09:17 AM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
SqlConnection conn = new SqlConnection(CONNECTION_STRING);

string strSQL = "select ActorID from Actor where ActorName = 'Name'";

SqlCommand cmd = new SqlCommand(strSQL,conn);

int intNumber;

conn.Open();

intNumber = (int) cmd.ExecuteScalar();

conn.Close();
That should be it. Remember to import your System.Data.SqlClient namespace.
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Share database over the Internet nitinkedia The Lounge 2 11-20-03 02:07 PM
SQL database registration form help vinhkhuong PHP 3 10-10-03 03:49 AM
tracking down a database problem ... bjmcintosh ASP 1 08-29-03 07:52 AM
Share database over the internet nitinkedia PHP 0 07-11-03 12:22 AM
Share database over the Internet nitinkedia New Members & Introductions 1 07-10-03 02:50 PM


All times are GMT -5. The time now is 01:01 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.