Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
F

Franklin Smith

@Franklin Smith
About
Posts
5
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Stored Procedure to Handle CSV
    F Franklin Smith

    All the code where I created the temp table and all works like a charm. The update/insert phase is where I have a problem. It has to do with my limited knowledge of SQL. Of course during all this I found out the data was being inserted wrong so I have to redo what I've already inserted which gives me a chance to fix the problem. Thank god it isn't live data. But I finally decided to go with

    SET ANSI_WARNINGS OFF
    MERGE PropertyLookupInformation as targetDB
    USING TempCsvImport as sourceDB
    ON targetDB.RealEstateNumber = sourceDB.RealEstateNumber
    WHEN MATCHED
    THEN
    UPDATE
    SET Name = sourceDB.Name
    ,StreetNumber = sourceDB.StreetNumber
    ,StreetName = sourceDB.StreetName
    ,Type = sourceDB.Type
    ,Direction = sourceDB.Direction
    ,Unit = sourceDB.Unit
    ,City = sourceDB.City
    ,ZipCode = sourceDB.ZipCode
    ,LastReviewed = CURRENT_TIMESTAMP
    WHEN NOT MATCHED BY TARGET
    THEN
    INSERT
    (PropertyID
    ,RealEstateNumber
    ,Name
    ,StreetNumber
    ,StreetName
    ,Type
    ,Direction
    ,Unit
    ,City
    ,ZipCode
    ,LastReviewed)
    VALUES
    ( NEWID()
    ,sourceDB.RealEstateNumber
    ,sourceDB.Name
    ,sourceDB.StreetNumber
    ,sourceDB.StreetName
    ,sourceDB.Type
    ,sourceDB.Direction
    ,sourceDB.Unit
    ,sourceDB.City
    ,sourceDB.ZipCode
    ,CURRENT_TIMESTAMP)
    ;

    The only thing I'm not sure of doing it this way is performance issues. Now just to get it put into a stored proc and we are set and ready to go.

    Database database algorithms help tutorial announcement

  • Stored Procedure to Handle CSV
    F Franklin Smith

    I know the bulk insert won't work on the CSV itself. I know that the below code is incorrect to do much of what I want. Problem is I don't know how make it all work together. The first part should work as is, I just need to pass the file name to the procedure. Edited the first part here to actually work. Plus adding in all the normalization updates I know need to be there.

    CREATE TABLE [dbo].[TempCsvImport](
    [RealEstateNumber] [nvarchar](11) NOT NULL,
    [Name] [nvarchar](100) NOT NULL,
    [StreetNumber] [nvarchar](10) NOT NULL,
    [StreetName] [nvarchar](50) NOT NULL,
    [Type] [nvarchar](10) NOT NULL,
    [Direction] [nvarchar](10) NULL,
    [Unit] [nvarchar](20) NULL,
    [City] [nvarchar](20) NOT NULL,
    [ZipCode] [nvarchar](10) NOT NULL)
    GO

    SET QUOTED_IDENTIFIER OFF

    DECLARE @fn varchar(8000)
    SELECT @fn = 'C:\Users\owner\Documents\Visual Studio 2010\Projects\UPA Data Miner\UPA Data Miner\bin\Debug\634556001928942124.csv'
    DECLARE @cmd varchar(8000)
    SET @cmd = "BULK INSERT dbo.[TempCsvImport] FROM '" + @fn + "' WITH(CODEPAGE='RAW',FIELDTERMINATOR = ',', ROWTERMINATOR='\n')"

    EXEC(@cmd)

    GO

    UPDATE [dbo].[TempCsvImport]
    SET [ZipCode] = SUBSTRING(ZipCode,1,5)
    WHERE LEN([ZipCode]) != 5

    GO

    UPDATE [dbo].TempCsvImport
    SET RealEstateNumber = REPLACE(RealEstateNumber,"-","")
    WHERE CHARINDEX("-",RealEstateNumber) != 0

    The next part is where I have no clue how to make it all work. The '@' parameters all have information from a record in the TempCsvImport

    /*For each record in TempCsvImport*/

    SELECT * FROM [dbo].[PropertyLookupInformation]
    WHERE [dbo].[PropertyLookupInformation].[RealEstateNumber] = @RealEstateNumber
    /*If a record is found*/
    UPDATE [dbo].[PropertyLookupInformation]
    SET [Name] = @Name
    ,[StreetNumber] = @StreetNumber
    ,[StreetName] = @StreetName
    ,[Type] = @Type
    ,[Direction] = @Direction
    ,[Unit] = @Unit
    ,[City] = @City
    ,[ZipCode] = @ZipCode
    ,[LastReviewed] = CURRENT_TIMESTAMP
    WHERE RealEstateNumber = @RealEstateNumber

    /*Otherwise insert*/

    INSERT INTO [dbo].[PropertyLookupInformation]
    ([PropertyID]
    ,[RealEstateNumber]
    ,[Name]
    ,[StreetNumber]
    ,[StreetName]
    ,[Type]
    ,[Direction]
    ,[Unit]
    ,[City]
    ,[ZipCode]
    ,[LastReviewed])
    VALUES
    ( NEWID()
    ,@RealEstateNumber

    Database database algorithms help tutorial announcement

  • Stored Procedure to Handle CSV
    F Franklin Smith

    I have done some searching, and I do understand how to do some of what I want to do. But I can't just do a bulk insert into the database I'm already using. Sample Data

    Real Estate Number,Owner,Street Number,Street,Street Type,Street Direction,Unit,City,Zip Code
    004306-5000,MANWARREN JAMES P,10933,BRIDGES,RD,,,Jacksonville,32225-
    013092-0164,WILSON DANTE J,8438,MC GIRTS VILLAGE,LN,,,Jacksonville,32225
    013100-1035,LEWIS GARNET A,4435,JACKSON HOLE,CT,,,Jacksonville,32225
    048496-0040,ALLEN JON R,2830,WICKWIRE,ST,,2,Jacksonville,32225-
    112862-1000,CITY OF JACKSONVILLE,0,FT CAROLINE,RD,,,Jacksonville,32225
    112863-0000,ONAS CORPORATION,0,FT CAROLINE,RD,,,Jacksonville,32225

    Database structure

    SELECT [PropertyID]
    ,[RealEstateNumber]
    ,[Name]
    ,[StreetNumber]
    ,[StreetName]
    ,[Type]
    ,[Direction]
    ,[Unit]
    ,[City]
    ,[ZipCode]
    ,[LastReviewed]
    FROM [DuvalFL].[dbo].[PropertyLookupInformation]

    PropertyID is a uniqueidentifier. It defaults to newid() LastReviewed is a datetime. I need to get the CSV file(File name changes each time) into a temp table. I don't have a problem with an actual table being made to do a temporary insert and then dropping it at the end of the procedure. Truncate the Zip Code field to 5 characters.(some of them have a "-" after the first 5 digits) If the Real Estate Number exists in the database then update the record. Otherwise Insert a new record. I could do all this from my program, but the DB is faster than using for or foreach statements to process each record.

    Database database algorithms help tutorial announcement

  • c# Webbrowser control with frames
    F Franklin Smith

    Thanks when I googled I must have been using the wrong search terms. I found a work around I just regexed the onload out of the body tag, then set the onload attribute the way I wanted it. Not the solution I wanted, but hey it works for what I needed. But doing it the right way will be more important when I start doing form fills on that page. I just wanted to keep this stupid popup alert that is in the body's onload event from activating.

    C# csharp help tutorial

  • c# Webbrowser control with frames
    F Franklin Smith

    I am trying to change the "onload" event of the Body in a frame. My problem is when I using the GetAttribute method on the Body it returns "System._ComObject" as a string rather than the attributes value. Please note it is not returning an object of System._ComObject, just the string. I tried just doing the change via Body.OuterHtml but that throws an expception of NotSupportedException. Which is odd seeing as it is a property that says it allows "get and set" operations. WebBrowser.Document.Window.Frames[i].Document.Body.GetAttribute("onload") = "System.__ComObject" Any ideas on how to get this to behave as it should would be greatly appreciated. Even just a point in maybe the right direction. Also I did try this using "mshtml" objects and all it got me was the actual System._ComObject. However, I had no idea how to covert that to the string it was supposed to actually represent.

    C# csharp help tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups