Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2015
    Posts
    6

    Unanswered: Vb.net Insert multilines in external database(access)

    Hi,

    Help,

    I try to add multilines to an access database with this code but...:


    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            
          
            Dim Connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\base_access.accdb"
            Dim Conn As New OleDb.OleDbConnection(Connstr)
            Dim sql As String = "SELECT mixa_id from cmixa"
            Dim cmd As New OleDb.OleDbCommand
    
            Dim da As New OleDb.OleDbDataAdapter
            Dim dt As New DataTable
           
            sql = "Insert into back (mixa_id) values (' " & TextBox1.Text & " ')"
          
    
    
            'sql = "Insert into back (mixa_id) values=  TextBox1.Text.Split(Environment.NewLine)"
    
    
    
    
              cmd.CommandText = sql
          
            Try
               
                cmd.Connection.Open()
               
                If cmd.ExecuteNonQuery() <> 0 Then
                  
                    MsgBox("As linhas foram inseridas correctamente na tabela")
                Else
                    MsgBox("ERRO: Os dados não foram inseridos!")
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                If cmd.Connection.State = ConnectionState.Open Then
                    'terminar a ligacao
                    cmd.Connection.Close()
                End If
            End Try
    
        End Sub


    With this code:

    Code:
    sql = "Insert into back (mixa_id) values (' " & TextBox1.Text & " ')"

    Already add, but only the first value of the table!!!


    And this:

    Code:
    Dim sCoolNewLine As String = ""
    sql = "Insert into back (mixa_id) VALUES('" & TextBox1.Text.Replace(vbNewLine, sCoolNewLine) & "')"
    give all the record but in the same line;

    12038120391204012041120421204312044120451204612047 12048120491205012051120521205312054120551205612057 120581205912060120611206212063

    Regards,

    Cachado

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    sorry I don't see what you are asking
    ...do you mean you want to add a chunk of text to the existing value in a column, in which case you'd use an update query

    if you want to force a line feed to separate chunks of text in a column use the vb constants vbcr, vblf or vbcrlf http://stackoverflow.com/questions/2...vbcr-constants

    you can fudge that by replacing say an escape string with the vbcrlf, eg

    say you choose /n to be your escape character to represent a linefeed
    your control is mycontrol

    in the CONTROL's before update event

    mycontrol.text = replace(mycontrol.text,"/n",vbcrlf)

    if its add a new line to say a contact conversation (with say a customer or sales prospect), then you'd have separate rows for each conversation, possibly is a memo column in a sub form
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2015
    Posts
    6
    textbox with more than one values:

    Click image for larger version. 

Name:	textbox_form.png 
Views:	2 
Size:	2.8 KB 
ID:	16599

    But when i press the button only the first record goes to database:

    Click image for larger version. 

Name:	access.png 
Views:	2 
Size:	10.0 KB 
ID:	16600

    This is the problem

  4. #4
    Join Date
    Jul 2015
    Posts
    6
    Or another solution will be possible to increase the database all the values of sql statement?

    Thks a lot,

    Cachado

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by jcachado View Post
    textbox with more than one values:

    Click image for larger version. 

Name:	textbox_form.png 
Views:	2 
Size:	2.8 KB 
ID:	16599

    But when i press the button only the first record goes to database:

    Click image for larger version. 

Name:	access.png 
Views:	2 
Size:	10.0 KB 
ID:	16600

    This is the problem
    ...check your tables
    it could be limited by the size of the column.. check its an appropriate size for the number of characters you expect to need.

    are you certain the data ins't there.....
    see if you alter the row height (move the cursor to the lowest part of the row, then click and drag the row to be taller / bigger)

    or try this query
    select mixa_id, len(mixa_id) from back
    ..then run it and see what results you get
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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