Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello, i have the made the following project:

I have made a V-Card, I can import this into my database but,
I can not show all the information I want..

Here is some parts of my code:

VB
'Private Sub voor het importeren van een V-Card:
Private Sub Importeren() _
    Handles itemImporteerVCard.Click, mnuImportVCard.Click, _
    btnImportVCard.Click                                    'Alle knoppen voor het importeren.

    Dim strBestand As String = String.Empty                 'Locatie + naam van het bestand.
    Dim strRegel As String = String.Empty                   'Regel/lijn.
    Dim strWaarde() As String = Nothing                     'de inhoud van de regels/lijnen.
    Dim objReader As System.IO.StreamReader = Nothing, _
        sbBuilder As System.Text.StringBuilder = Nothing

    'Variabelen:
    '--------------------------------
    Dim intNummer As Integer = "111114"                     'een nummer kan maar één keer voorkomen.
    Dim strSoort As String = "D"                            'D = Debiteuren, C = Crediteuren, R = Relaties.
    Dim strNaam As String = " "                             'de naam die in de V-Card staat.
    Dim strVoornaam As String = " "                         'Voornaam.

    Dim strTelefoon As String = " "                         'Deze String moet nog aangepast worden,
    Dim strTelWerk As String = " "                          'strTelwerk en strTelThuis zijn samen strTelefoon.
    Dim strTelThuis As String = " "

    Dim strMobiel As String = " "                           'Mobiel nummer.
    Dim strOverig As String = " "                           'Overige telefoon nummers.

    Dim strFax As String = " "                              'Ook hier worden strFaxWerk + Thuis samen strFax.
    Dim strFaxWerk As String = " "
    Dim strFaxThuis As String = " "

    Dim strAdres As String = " "
    Dim strPostcode As String = " "
    Dim strPlaats As String = " "
    Dim strAdresgegevens As String = (strAdres) & (strPostcode) & (strPlaats)




    Dim strWebsite As String = " "
    Dim strUrlThuis As String = " "
    Dim strUrlWerk As String = " "

    Dim strMail As String = " "
    Dim strZoek As String = "testtest"



That are my strings and here I have import thes strings into cases:

SQL
'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.
            strAdresgegevens = 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



The Next step is to INSERT INTO Database:

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_mobielnr, B22_faxnummer, " _
                & "B22_email, B22_www_adres, B22_zoeknaam) " _
                & " VALUES (" & intNummer & ", '" & strSoort & "', '" & strNaam & "', '" & strVoornaam _
                & "', '" & strAdres & "', '" & strPostcode & "', '" & strPlaats & "', '" & strTelefoon _
                & "', '" & strMobiel & "', '" & strFax & "', '" & strMail & "', '" & strWebsite & "', '" & strZoek & "' )"

Dim ds_B22 As New OdbcCommand                       'ds_B22 is de tabel Relaties.
ds_B22.CommandType = Data.CommandType.Text
ds_B22.CommandText = strInsert
ds_B22.Connection = cnn
ds_B22.ExecuteNonQuery()



This is the info I can not show when I run the app:
strAdres, strPostcode, strPlaats -> must be one string
strTelThuis & strTelWerk -> must be one string
strFaxThuis & strFaxWerk -> must be one string
strEmail & strWebsite -> must be one string.

do you know how i can do this?
thanks.
Posted

I recommend using the string.format function. For you address for example I would :

VB
String.Format("{0}, {1}, {2}", strAdres, strPostcode, strPlaats)
 
Share this answer
 
Comments
Sandeep Mewara 9-Jun-12 1:19am    
5!
db7uk 11-Jun-12 5:26am    
Cheers!
OdeJong, where is a problem?

To concate strings, use:
VB
sStrConcat = sString1 & sString2

or StringConcat[^] method.

Based on your code:
Example 1:
VB
strInsert = "INSERT INTO Relaties (B22_relnr, B22_rel_soort, B22_naam, B22_voornaam_etc, " _
                & "B22_adres, B22_postcode, B22_plaats, B22_telefoon1, B22_mobielnr, B22_faxnummer, " _
                & "B22_email, B22_www_adres, B22_zoeknaam) " _
                & " VALUES (" & intNummer & ", '" & strSoort & "', '" & strNaam & "', '" & strVoornaam _
                & "', '" & strAdres & strPostcode & strPlaats "', '" & strPostcode & "', '" & strPlaats & "', '" & strTelefoon _
                & strTelThuis & strTelWerk & "', '" & strMobiel & "', '" & strFax & strFaxThuis & strFaxWerk & "', '" & strMail & "', '" & strWebsite & "', '" & strZoek & "' )"
'and so on...
MessageBox (strInsert)


Example 2:
VB
MessageBox (String.Concat(strAdres, String.Concat(strPostcode, strPlaats)))


Read more about: Operators[^]
 
Share this answer
 
Comments
Sandeep Mewara 9-Jun-12 1:20am    
Good answer. 5!
Maciej Los 10-Jun-12 12:03pm    
Thank you ;)
OdeJong 11-Jun-12 5:09am    
thanks u2 for both the answers! i give u2 5stars! but one question:

I have no as result:

strTelThuis + strWerk in one field of my table. Can I write a code that I can use one of these two? so if I have both numbers then let show strWerk. If have one of these two than show the one I have..

Do you know how to do that?

Thanks!
db7uk 11-Jun-12 5:31am    
If we are talking about sql insert then you would need to use the CASE statement. If in code then you could use the SELECT CASE or if... If you answer by posting a new question then I / We / someone can give a solution. Thanks for the *'s !!!

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