Problems with Batch Update...doh!

Hi-

Here's the scenario. I'm retrieving data from two different tables. Once I get this data I am looping through the data and I have to update a couple columns in the same table. Doesn't anyone know of where I can find a good example of this. I've been looking every where for this. 

Example: 

Stored Proc: 

SELECT IL.listing#, IL.imageID, o.brokerNum, IL.imageStatus, o.companyid, 
L.ListingID AS 'L_ListingID', IL.listingID AS 'IL_ListingID' 
FROM ImageListings IL 
JOIN listings L ON IL.listing# = L.listing# 
AND (IL.SourceMLS = L.SourceMLS 
OR IL.SourceMLS = '') 
JOIN Offices O ON o.officeid = l.officeid 
WHERE IL.imageStatus in(1,6) 

I need to loop through the dataset and update the image status of particuliar rows with a company id of a certain number within the ImageListings table. 

Can someone explain a simple way to do this  I would appreciate it greatly. 

Thanks, 
Rick


Answer this question

Problems with Batch Update...doh!

  • NickGetz

    Ack! Didn't see your reply until now! Do you have this solved

    But the short answer is that yes, you can use that general idea to batch updates in a DataSet.

    Don

  • Andre_B

    Hey Don-

    Thanks for the reply, I figured it out using the command builder, but I ran into another issue related to this.  I was wondering if you know of a way to insert multiple records without using the command builder. I have to loop through a directory of files and depending on how many files there are is how many inserts that I have to do. There could be hundreds of files. I would rather try to to some sort of batch insert rather than do an insert each time it loops through.   Does that make sense

    Code example

    For Each strFileName In strFiles
                        strFileDestPath = "C:\SomePath\" & lngNextNum & ".jpg"
                        Dim objFileInfo As New FileInfo(strFileName)

                        strFile = Mid(strFileName, InStrRev(strFileName, "\") + 1)
                        Row = objDataSet.Tables("ImageListings").NewRow
                        Row("listing#") = getListNum(strFile)
                        Row("ImageID") = lngNextNum
                        Row("ImageDate") = getGoodDate(CStr(objFileInfo.LastWriteTime))
                        Row("ImageSize") = objFileInfo.Length
                        Row("sourceMLS") = p_strSourceMls
                        Row("ImageStatus") = 1
                        Row("Status") = getStatus(p_strPrimExt, strFile)
                        Row("Revised") = Now()
                        objDataSet.Tables("ImageListings").Rows.Add(dsRow)

               
                        lngNextNum += 1

     Next strFileName

    Batch Insert after I get all the data
     
    Don't necessarily need to use a dataset.  Just looking for a new direction or ideas.  I'm in a rush, so might not make complete sense

    Thanks

  • Olaf van der Spek

    Hi Rick,

    I assume that you are looping through the results using something like a DataReader or a DataSet object  If so, you can create a new command object and do an UPDATE for each row that you need to do. there are lots of ways to do this, so you might post the client code you're using with this SQL statement.

    OTOH, if you are updating every row you may be able to do it through a single SQL statement. What kind of changes are you making

    Don

  • Jason_OPIS

    you can do this within stored procedure, may be using table function to return the "company id of a certain number ", or do subselect, doing this in code is unecessary , i presume

    the function


    create function fn_tab_comopany_certain_number
    as
    /*
    RETURNS @table_var TABLE 
    (c1 int, 
     c2 int)
    */
    SELECT IL.listing#, IL.imageID, o.brokerNum, IL.imageStatus, o.companyid, 
    L.ListingID AS 'L_ListingID', IL.listingID AS 'IL_ListingID' 
    FROM ImageListings IL 
    JOIN listings L ON IL.listing# = L.listing# 
    AND (IL.SourceMLS = L.SourceMLS 
    OR IL.SourceMLS = '') 
    JOIN Offices O ON o.officeid = l.officeid 
    WHERE IL.imageStatus in(1,6) 



  • Problems with Batch Update...doh!