Results 1 to 10 of 10

Thread: Fixing the "date"

Threaded View

  1. #1

    Thread Starter
    Lively Member anamada's Avatar
    Join Date
    Jun 2011
    Location
    Philippines, Makati
    Posts
    107

    Fixing the "date"

    I am using MS SQL SERVER 2008 R2 database from my VB.NET program.

    I want to find a way to fix my problem. My problem is that some of the records(date) in the files that I imported from textfile are like this "105" where it should be "000105(00-01-05)".What I did to fix the prob for the mean time is that instead of "date", I assigned them as "int". But now, it needs to be in "date" format. Im having problem with those "Zeros". Is there any way where I can import the records as date(yy-mm-dd) and not int? I also tried to change and assign them as date in MS SQL SERVER 2008 R2 but im getting an error. I think the problem is that it cant be recognized as date because some records consist 3-5 digits only, where it should be 6 digits for them to be recognized as date (yymmdd)
    Attached is a sample screenshot of sample record.

    Here's my code of migration:
    Code:
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim files As ReadOnlyCollection(Of String)
            files = My.Computer.FileSystem.GetFiles("C:\TEXTFILE", FileIO.SearchOption.SearchAllSubDirectories, "*.txt")
            For Each a As String In files
                Dim filename As String = a
                Dim fields As String()
                Dim delimiter As String = "|"
                Dim connectionString As String
    
                Using parser As New TextFieldParser(filename)
                    parser.SetDelimiters(delimiter)
                    While Not parser.EndOfData
                        ' Read in the fields for the current line
                        fields = parser.ReadFields()
                        ' Add code here to use data in fields variable.
    
                        'INSERT STATEMENT HERE
                        connectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=****;Integrated Security=True;User Instance=True"
                        Using connection As New SqlConnection(connectionString)
    
    
                            'Dim insert As New SqlCommand("INSERT INTO Certmast (CER_HOLD_CODE,CER_CERT_CODE, CER_CERT_ISSUE_DATE, CER_NOSHARES, CER_REASON_CODE, CER_CUR_STATUS, CER_PREV_STATUS, CER_ORIGIN_STK_CODE, CER_ORIGIN_CERT_CODE, CER_ORIGIN_REASON_CODE, CER_LOSS_PUB_DATE, CER_UPDATE_DATE, CER_USER_ID) " _
                            '                                            & "VALUES (@CER_HOLD_CODE,@CER_CERT_CODE, @CER_CERT_ISSUE_DATE, @CER_NOSHARES, @CER_REASON_CODE, @CER_CUR_STATUS, @CER_PREV_STATUS, @CER_ORIGIN_STK_CODE, @CER_ORIGIN_CERT_CODE, @CER_ORIGIN_REASON_CODE, @CER_LOSS_PUB_DATE, @CER_UPDATE_DATE, @CER_USER_ID)", _
                            '        connection)
    
    
    
                            'insert.Parameters.AddWithValue("@CER_HOLD_CODE", fields(0).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_CERT_CODE", fields(1).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_CERT_ISSUE_DATE", fields(2).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_NOSHARES", fields(3).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_REASON_CODE", fields(4).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_CUR_STATUS", fields(5).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_PREV_STATUS", fields(6).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_ORIGIN_STK_CODE", fields(7).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_ORIGIN_CERT_CODE", fields(8).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_ORIGIN_REASON_CODE", fields(9).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_LOSS_PUB_DATE", fields(10).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_UPDATE_DATE", fields(11).Trim.ToString)
                            'insert.Parameters.AddWithValue("@CER_USER_ID", fields(12).Trim.ToString)
    
                            'insert.Connection.Open()
                            'insert.ExecuteNonQuery()
                            'insert.Connection.Close()
    Attached Images Attached Images  
    We live and learn

    -Jm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width