[RESOLVED] Update command in vb.net,asp.net
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] Update command in vb.net,asp.net

  1. #1
    Join Date
    Feb 2011
    Posts
    15

    [RESOLVED] Update command in vb.net,asp.net

    hi Everyone,
    My program is doing good when I suddenly bumped into this problem.
    I dont know how to do the next functionality that I need to accomplish.
    I am done with inserting values, showing the gridview etc and it works great. Now my problem is the update command.

    I have 2 tables
    table:tblDest
    Fields:
    destLastName
    destFname
    destEmail

    Table:tblSource
    Fields:
    Sourcelastname
    SourceFname
    SourceEmai

    Now, when I run my update command in sql server, it works great! I just right click the database, click new query and i run this command:
    update tblDest set DestEmail =(Select SourceEmail from tblSource where tblSource.SourceFname = tblDest.DestFname and tblSource.SourceLastname = tblDest.DestLastname)
    what the query does, is it updates the table tbldest email where lastname and firstname exists in both tables that are equal,
    the question is, I want to automate this, I am done with inserting values, the problem is, I dont know how to run the update command,
    I tried doing this:
    Dim sqlds As New SqlDataSource
    sqlds.ConnectionString = ConfigurationManager.ConnectionStrings("sqlconnect").ConnectionString
    sqlds.ProviderName = ConfigurationManager.ConnectionStrings("sqlconnect").ProviderName
    sqlds.UpdateCommand = "update tblDest set DestEmail =(Select SourceEmail from tblSource where tblSource.SourceFname = tblDest.DestFname and tblSource.SourceLastname = tblDest.DestLastname)"
    DestGrid.DataSource = sqlds
    DestGrid.DataBind()
    but nothing happened.

    I want to thank you guys in advance for any help.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: Update command in vb.net,asp.net

    SQL uses this format:


    Code:
        UPDATE table
        SET column = expression
        WHERE predicates;
    http://www.techonthenet.com/sql/update.php
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2011
    Posts
    15

    Re: Update command in vb.net,asp.net

    Thanks dglienna

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Update command in vb.net,asp.net

    two things....

    #1 : Have you checked the tables to see if the update has occured?? The command should complete regardless of the Where part of the statement. It's quite posible that tblSource is not been updated in the first place. and hence wont update tblDest ....

    #2 : the code you end off with
    Code:
    DestGrid.DataSource = sqlds
    DestGrid.DataBind()
    will not work as you intend it too, as an update command does not return a dataset. however i also noticed that you've given the SqlDataSource an Update String but have not told it to execute it...

    so your code should look a little like this..
    Code:
    Dim sqlds As New SqlDataSource
    sqlds.ConnectionString = ConfigurationManager.ConnectionStrings("sqlconnect").ConnectionString
    sqlds.ProviderName = ConfigurationManager.ConnectionStrings("sqlconnect").ProviderName
    sqlds.UpdateCommand = "update tblDest set DestEmail =(Select SourceEmail from tblSource where tblSource.SourceFname = tblDest.DestFname and tblSource.SourceLastname = tblDest.DestLastname)"
    sqlds.Update
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  5. #5
    Join Date
    Feb 2011
    Posts
    15

    Talking Re: Update command in vb.net,asp.net

    Thank you GremlinSA for the detailed explanation.

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center