Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the V-Card code that i must INSERT INTO my Database:

CSS
ADR;WORK;PREF:;;Sjoerd Veltmanstraat 15;Drachten;;9203 NJ
ENCODING=QUOTED-PRINTABLE:Sjoerd Veltmanstraat 15
URL;HOME:www.epixfotostudio.nl
URL;WORK:www.epixfotostudio.nl
EMAIL;PREF;INTERNET:odejong@epixfotostudio.nl
END:VCARD


This is my code in VB.Net:

VB
Dim strAdres As String = " "                            'Adres.
Dim strPostcode As String = " "                         'Postcode.
Dim strPlaats As String = " "                           'Woonplaats.

Dim strUrlThuis As String = " "                         'Website, privé en zakelijk.
Dim strUrlWerk As String = " "

Dim strMail As String = " "                             'E-mail adres.
Dim strZoek As String = "testtest"                      'Zoeknaam: eerste 4 letters van naam en v.d. woonplaats.

'Bevestiging voor het importeren:
If MsgBox("Wilt u een v-Card Importeren?", 36, "Bevestiging voor het importeren") _
    = MsgBoxResult.Yes Then
    Try
        strBestand = "c:/Test.vcf"                      'Verwijst naar de locatie van het bestand.
        sbBuilder = New System.Text.StringBuilder       'Er is een nieuwe stringbuilder gemaakt.
        frmVCard.txtVCard.Text = strBestand             'frmVcard.txtVcard.Text moet gevuld worden
        'met de inhoud van het bestand.

        objReader = New System.IO.StreamReader(strBestand)

        'Eigenschappen voor het openen van de V-Card:
        ofdImport.Filter = "V-Cards (*.vcf)|*.vcf"      'Filter betreft de extensie van het bestand *.vcf.
        ofdImport.FileName = "*.vcf"                    'Bestandsnaam: alles.vcf.
        ofdImport.Title = "V-Card importeren"           'Titel van het dialoogvenster voor het openen.

        If ofdImport.ShowDialog = System.Windows.Forms.DialogResult.OK Then
            objReader = New System.IO.StreamReader(strBestand)
            'frmVCard.Show()                             'Laat de form zien waar de Vcard in terecht komt.
        End If

        Do While objReader.Peek >= 1
            strRegel = objReader.ReadLine()             'Elke regel/lijn wordt 1 voor 1 gelezen.
            strWaarde = strRegel.Split(":")             'De waarde van elke regel wordt gesplits d.m.v. ":"

            'Onderstaande Boolean zorgt ervoor dat dubbele info weg gehaald worden.
            '----------------------------------------------------------------------
            Dim blnDubbel As Boolean

            Select Case UCase(strWaarde(0))             '(0) = het gedeelte voor ":" en (1) komt daarna.
                Case "BEGIN", "VERSION", "END"          'De waarden die niet worden getoond.

                Case "N"
                    strNaam = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbTab)

                Case "FN"                               'Voornaam.
                    strVoornaam = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbCrLf)

                Case "TEL;WORK;VOICE"                   'Telefoon op het werk.
                    If blnDubbel = False Then
                        strTelWerk = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbTab)
                        blnDubbel = True
                    End If

                Case "TEL;HOME;VOICE"                   'Telefoon thuis.
                    strTelThuis = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbCrLf)

                Case "TEL;CELL;VOICE"                   'Mobiele telefoon.
                    strMobiel = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbTab)

                Case "TEL;VOICE"                        'Overige nummers.
                    strOverig = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbCrLf)

                Case "TEL;WORK;FAX"                     'Fax op het werk.
                    strFaxWerk = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbTab)

                Case "TEL;FAX"                          'Fax thuis.
                    strFaxThuis = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbCrLf)

                Case "ADR;WORK;PREF:"                   'Adres.
                    strAdres = strWaarde(1) & ";;" & " " & ";" & " "
                    sbBuilder.Append(strWaarde(1) & vbCrLf)

                Case "ENCODING=QUOTED-PRINTABLE:"
                    strAdres = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbCrLf)

                Case "URL;HOME:"                        'Website Thuis.
                    strUrlThuis = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbTab)

                Case "URL;WORK:"                        'Website Werk.
                    strUrlWerk = strWaarde(1)
                    sbBuilder.Append(strWaarde(1) & vbCrLf)

                Case "EMAIL;PREF;INTERNET:"             'Email adres.
                    strMail = strWaarde(1)
                    sbBuilder.Append(strWaarde(1))

                Case Else
                    sbBuilder.Append(strWaarde(1) & vbCrLf)

            End Select
        Loop                                            'Het proces wordt herhaald.
        objReader.Close()
        'frmVCard.txtVCard.Text = sbBuilder.ToString



This is how I have INSERT al my info..but The Adres, Postcode en Plaats is stil not inserted.. the sam with UrlThuis & UrlWerk + my strMail:

VB
'INSERT & VALUES lijst:
                strInsert = "INSERT INTO Relaties (B22_relnr, B22_rel_soort, B22_naam, B22_voornaam_etc, " _
                                & "B22_adres, B22_postcode, B22_plaats, B22_telefoon1, B22_telefoon2, " _
                                & "B22_mobielnr, B22_faxnummer, B22_email, B22_www_adres, B22_zoeknaam) " _
                                & " VALUES (" & intNummer & ", '" & strSoort & "', '" & strNaam _
                                & "', '" & strVoornaam & "', '" & strAdres & strPostcode & strPlaats _
                                & "', '" & strPostcode & "', '" & strPlaats & "', '" & strTelWerk _
                                & "', '" & strTelThuis & "', '" & strMobiel & "', '" & strFaxWerk _
                                & "', '" & strMail & "', '" & strUrlWerk & "', '" & strZoek & "' )"

                Dim ds_B22 As New OdbcCommand                       'ds_B22 is de tabel Relaties.
                ds_B22.CommandType = Data.CommandType.Text
                ds_B22.CommandText = strInsert      'Zorgt ervoor dat de informatie wordt toegevoegd aan de database.
                ds_B22.Connection = cnn
                ds_B22.ExecuteNonQuery()

                If MsgBox("De V-Card is geïmporteerd", 0, "V-Card is geïmporteerd") Then

                    Exit Sub
                End If



Can someone help me with this or help me in the good direction?
thanks!!
Posted

Try using Parameterized queries instead of concatenating your strings: it is safer, neater and easier to read:
VB
Using con As New SqlConnection(strConnect)
	con.Open()
	Using com As New SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con)
		com.Parameters.AddWithValue("@C1", myValueForColumn1)
		com.Parameters.AddWithValue("@C2", myValueForColumn2)
		com.ExecuteNonQuery()
	End Using
End Using
This means that the data passed into the database is exactly what is in teh data, do if it contains unecpected information (such as a quote, or a semicolon) it doesn't mess up the transfer.

Concatenating strings is a very bad idea, it leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database.
 
Share this answer
 
Comments
OdeJong 12-Jun-12 4:16am    
o.k. thanks! I will take a look for it and I will try to use your solution. Thanks!
OdeJong 12-Jun-12 7:03am    
I have tried your solution but I have restore my own code because it was not working like i want it to.

The peace of the adres, postcode, plaats is still not insert into the database. Thanks for your help so far, i will try something else.
Check your DataTypes and Size of the Fields in your Table (DataBase Table).

Increase the Size Of address or the one having longer values.
 
Share this answer
 
v2
Comments
OdeJong 12-Jun-12 8:42am    
it's still not working
Karwa_Vivek 12-Jun-12 8:46am    
Use BreakPoints and Watch the Values.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900