SQL problems

Rate It (1)

Last post 07-27-2007 3:27 PM by DanGarc. 2 replies.

Sort Posts:

  • SQL problems

    07-27-2007, 2:13 PM
    • Loading...
    • DanGarc
    • Joined on 07-27-2007, 2:04 PM
    • NYC
    • Posts 6

    I'm currently working on a web application *in Visual Studio 2005* that requires an SQL database. My SQL statements look like this:

     

    sql = "UPDATE Login 
    SET
    BornValue = @BornValue,
    GraduateValue = @GraduateValue,
    MarriedValue= @MarriedValue,
    ChildrenValue= @ChildrenValue,
    DependentValue = @DependentValue,
    DeceasedValue = @DeceasedValue,
    VeteranValue = @VeteranValue, Return2005Value = @Return2005Value, Leased2005Value = @Leased2005Value, Leased2006Value = @Leased2006Value, Federal2005Value = @Federal2005Value, Federal2006Value = @Federal2006Value, Federal2007Value = @Federal2007Value, Gift2005Value = @Gift2005Value, Gift2006Value = @Gift2006Value, Gift2007Value = @Gift2007Value WHERE
    Ident = (VB GUID VARIABLE)"
    Dim cmd As New SqlCommand(sql, Connection) ... cmd.Connection.Open() cmd.ExecuteNonQuery() cmd.Connection.Close()

     My problem is that at (VB GUID VARIABLE), I want to compare the column "Ident" against my VB generated GUID, which is stored in a session-- 'Session("GUID")'.

     The session works properly, there are no issues with that, I just need to know how to pass the Session variable into the SQL statement, allowing for a comparison in the tables.

     Can anyone help me out? Greatly appreciated.

    "Education is what remains after one has forgotten everything he learned in school."
  • Re: SQL problems

    07-27-2007, 3:18 PM
    Answer
    • Loading...
    • dbland07666
    • Joined on 05-15-2007, 2:02 PM
    • Wall Street
    • Posts 697

    Don't understand what you're asking -- how to get Session("GUID") into a VB variable or how to pass parameters (same way as you would all those other parameters)???

    - David

    Please click "Mark as Answer" on all posts that help you.
  • Re: SQL problems

    07-27-2007, 3:27 PM
    • Loading...
    • DanGarc
    • Joined on 07-27-2007, 2:04 PM
    • NYC
    • Posts 6

    Actually, yeah, I just figured it out. I just had to create another scaler variable, then define the variable just as I did the others.

     I know SQL but really... this integration with VB is seriously hurting my head. Thanks for the point in the right direction!

     The final output looked like this--

     

    sql = "UPDATE Login SET
     BornValue = @BornValue,
     GraduateValue = @GraduateValue,
     MarriedValue= @MarriedValue,
     ChildrenValue= @ChildrenValue,
     DependentValue = @DependentValue,
     DeceasedValue = @DeceasedValue,
     VeteranValue = @VeteranValue,
     Return2005Value = @Return2005Value,
     Leased2005Value = @Leased2005Value,
     Leased2006Value = @Leased2006Value,
     Federal2005Value = @Federal2005Value,
     Federal2006Value = @Federal2006Value,
     Federal2007Value = @Federal2007Value,
     Gift2005Value = @Gift2005Value,
     Gift2006Value = @Gift2006Value,
     Gift2007Value = @Gift2007Value 
    WHERE
     Ident = @Guid"
    
            Dim cmd As New SqlCommand(sql, Connection)
    ...
    'This was the added parameter, I feel slightly ridiculous now. Watch that SQL syntax up top!
            cmd.Parameters.AddWithValue("@Guid", Session("GUID"))
    
    
            cmd.Parameters.AddWithValue("@BornValue", Me.Born)
            cmd.Parameters.AddWithValue("@GraduateValue", Me.Graduate)
            cmd.Parameters.AddWithValue("@MarriedValue", Me.Married)
            cmd.Parameters.AddWithValue("@ChildrenValue", Me.Children)
            cmd.Parameters.AddWithValue("@DependentValue", Me.Dependent)
            cmd.Parameters.AddWithValue("@DeceasedValue", Me.Deceased)
            cmd.Parameters.AddWithValue("@VeteranValue", Me.Veteran)
            cmd.Parameters.AddWithValue("@Return2005Value", Me.Return2005)
            cmd.Parameters.AddWithValue("@Leased2005Value", Me.Leased2005)
            cmd.Parameters.AddWithValue("@Leased2006Value", Me.Leased2006)
            cmd.Parameters.AddWithValue("@Federal2005Value", Me.Federal2005)
            cmd.Parameters.AddWithValue("@Federal2006Value", Me.Federal2006)
            cmd.Parameters.AddWithValue("@Federal2007Value", Me.Federal2007)
            cmd.Parameters.AddWithValue("@Gift2005Value", Me.Gift2005)
            cmd.Parameters.AddWithValue("@Gift2006Value", Me.Gift2006)
            cmd.Parameters.AddWithValue("@Gift2007Value", Me.Gift2007)
    
            cmd.Connection.Open()
            cmd.ExecuteNonQuery()
            cmd.Connection.Close()
     
    "Education is what remains after one has forgotten everything he learned in school."
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter