If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Can someone help me on sql UPDATE, SELECT WHERE

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-05-10, 11:50
Abrahm75 Abrahm75 is offline
Registered User
 
Join Date: Feb 2009
Location: Sweden
Posts: 19
Question Can someone help me on sql UPDATE, SELECT WHERE

This is the scenario is that am using sql server and c#.net trying to read from table using SELECT to read an value (contractId) as below code;

Code:
SqlDataReader reader8;
            SqlCommand comm8;
            SqlConnection conn8;
            string connectionString8 = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
            conn8 = new SqlConnection(connectionString8);
            string sqlcomm8 = "SELECT contractId FROM contract WHERE (Seid ='" + susid + "')";
            comm8 = new SqlCommand(sqlcomm8, conn8);
            // Open the connection
            conn8.Open();
            reader8 = comm8.ExecuteReader();
            reader8.Read();
            p7 = Convert.ToInt32(reader8["contractId"]);
            reader8.Close();
            conn8.Close();
that i can get it to another sql code using UPDATE ;

Code:
SqlCommand comm9;
            SqlConnection conn9;
            string connectionString9 = ConfigurationManager.ConnectionStrings["DBConnectionString1"].ConnectionString;
            conn9 = new SqlConnection(connectionString9);
            string sqlcomm9 = "UPDATE Booking SET contractId =" + p7 + " WHERE (Seid ='" + susid + "')";
            comm9 = new SqlCommand(sqlcomm9, conn9);
            // Open the connection
            conn9.Open();
            // Execute the command
            comm9.ExecuteNonQuery();
            conn9.Close();
So, am using tow sql statment SELECT and UPDATE to get the value from a table to another.
My question is. Is there an sql query that i can UPDATE from SELECT WHERE Seid='" + susid + "'.
please if there a way to do that please state or tell me an a good way to do it in c#.net programming.

thanks alot in advance ...
Reply With Quote
  #2 (permalink)  
Old 03-05-10, 12:10
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Reply With Quote
  #3 (permalink)  
Old 03-07-10, 07:41
Abrahm75 Abrahm75 is offline
Registered User
 
Join Date: Feb 2009
Location: Sweden
Posts: 19
Hi, i checked the posted link, but i didn't get what its mean, could you please post something deals with my problem !!! I'll be so grateful
Reply With Quote
  #4 (permalink)  
Old 03-07-10, 07:55
PracticalProgram PracticalProgram is offline
Registered User
 
Join Date: Sep 2001
Location: Chicago, Illinois, USA
Posts: 551
Is this what you are looking-for?

Code:
UPDATE  Booking
SET     Booking.contractId = Contract.contractId
FROM    Booking
INNER
JOIN    Contract on
            Contract.Seid=Booking.Seid
WHERE   Booking.Seid ='" + susid + "'";
__________________
Ken

Maverick Software Design

(847) 864-3600 x2
Reply With Quote
  #5 (permalink)  
Old 03-08-10, 09:04
Abrahm75 Abrahm75 is offline
Registered User
 
Join Date: Feb 2009
Location: Sweden
Posts: 19
Thanks alot Ken, its working ...
Reply With Quote
Reply

Tags
.net, c#.net, sql server

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On