Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009
    Location
    Sweden
    Posts
    19

    Question Unanswered: 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 ...

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    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

  4. #4
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    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

  5. #5
    Join Date
    Feb 2009
    Location
    Sweden
    Posts
    19
    Thanks alot Ken, its working ...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •