i am trying to read a 2 way delimited txt file into sqlserver in C# 2008.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • indona
    New Member
    • Jul 2010
    • 9

    #1

    i am trying to read a 2 way delimited txt file into sqlserver in C# 2008.

    i am trying to read a 2 way delimited txt file into sqlserver in VS2008 using C# and SQL server2005. the individual entries of the file are delimited by "~" and the data within the entries are separated using "$". and i need to read the entries as rows in the database and the data within each entry i.e. delimited by $ as columns or fields in the database.

    since i am new to .net, i am not able to do the 2 way delimiting and read all the rows into the database.

    here is a pattern of the data we are dealing with...

    *************** *************** *************** ***********
    12:02:16 AM$206.79.184.1 23$eejyaqmgcm0c dj45apdeeu55$Av ailability$Gene ral network error.~
    12:02 AM$170.35.208.2 2$bo1lbm455s1di 245asulqrjc$onl ine_booking.asp x$Object reference not set to an instance of an object.~

    *************** *************** *************** ***********

    as u can see, ~ separates two different entries...i.e to be entered as rows in the database. and $ separates the data within each entry...i.e the columns inside each row in the database.

    i would be very thankful if u could help me in this matter as soon as possible.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Have a look at the String.Split method.

    You can use it to tokenize your source string by ~. Then use it again on each token returned by the first split to further tokenize those lines by #.

    Also, note that in the second token (by ~) you've got a space in one of the items.. "online_b oooking.aspx" instead of "online_booking .aspx". Typo? Maybe check your source file.

    Try playing with String.Split and let us know if you have any questions! :)

    Comment

    • indona
      New Member
      • Jul 2010
      • 9

      #3
      thanks a lot for the reply. i have just done the reading of the file with the split function by displaying the lines onto cmd. thanks a lot for the help.
      but i am still not sure about the part of reading the data into the database. can you plz help me with some sample code for this.

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        Sorry, I'm not overly experienced with working with databases, nor do I have your setup. If it's a DataSet you're putting it into, and each delimited item represents a column, you should be able to tell the column number by the index in the split array.

        I dunno if that helps or not...

        Comment

        • indona
          New Member
          • Jul 2010
          • 9

          #5
          okay.... i will try with d index part u just mentioned..
          anyway thanks a lot..

          Comment

          Working...