Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 81

Thread: Save results from textbox to sdf table

  1. #41

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Name:  11.jpg
Views: 271
Size:  6.7 KB

    The sdf is a internal table, can you see in image?

    Thks,
    Cachado

  2. #42
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    It's blurry.

    Do you have two different connection strings - one in Load() and one in the button click? Is either working?

    Didn't the connection work in button click earlier, because you were getting a syntax error when you tried to insert, so that at least meant you had gotten connected.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  3. #43

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Quote Originally Posted by MMock View Post
    It's blurry.

    Do you have two different connection strings - one in Load() and one in the button click? Is either working?

    Didn't the connection work in button click earlier, because you were getting a syntax error when you tried to insert, so that at least meant you had gotten connected.
    But I need two, one for Informix collect data and another to add records in sdf table, right?

    how can I solve this? Almost get what I want, I can not die on the beach


  4. #44
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Yes, that's fine if you need two. You can have 10 if you need them!

    So let me ask this again - the one to the sdf table, wasn't that working previously? The connection was working, but your INSERT command had a problem which we saw in your post that examined CommandText of the command object. Is that right?

    P.S. I'm not sure what dying on the beach is, but it sounds like a nice way to go when the time comes...
    Last edited by MMock; Oct 28th, 2015 at 10:05 AM. Reason: post script
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  5. #45

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    But at the moment it seems that is working and that the error message is as follows:

    ERROR [42S02] [INTERSOLV][ODBC Informix driver][Informix]The specified table (testebd) is not in the database.

    Code:
    mports System.Data.Odbc
    Imports System.Data.SqlClient
    Imports System.Configuration
    Imports System.Data.OleDb
    
    Public Class teste
    
    
    
        Private Sub teste_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'If e.KeyChar = Chr(13) Then
            Dim con As New Odbc.OdbcConnection("Dsn=informix;DATABASE=system;host=exe;serv=onlinet;srvr=onlinet;pro=onsoctcp;uid=user;pwd=test")
            Dim com As New Odbc.OdbcCommand("SELECT mixa_id from cmixa", con)
            Dim da As New Odbc.OdbcDataAdapter(com)
            Dim dr As Odbc.OdbcDataReader
    
    
    
            con.Open()
            dr = com.ExecuteReader
    
    If dr.HasRows Then
                While dr.Read()
    
                    TextBox1.Text = TextBox1.Text + dr("mixa_id").ToString + Environment.NewLine
    
    
    
                End While
            End If
    
            dr.Close()
    
            con.Close()
    
    
            ' Create an unbound DataGridView by declaring a column count.
            DataGridView1.ColumnCount = 1
            DataGridView1.ColumnHeadersVisible = True
    
            ' Set the column header names.
            DataGridView1.Columns(0).Name = "mixa_id"
          
    
    
    
            con.Open()
            dr = com.ExecuteReader
    
            If dr.HasRows Then
                While dr.Read()
    
    
                    Me.DataGridView1.Rows.Add(dr.Item("mixa_id"))
    
    
                End While
            End If
    
            dr.Close()
    
            con.Close()
    
           
            con.Open()
            For Each rw As DataGridViewRow In DataGridView1.Rows
                com = New Odbc.OdbcCommand("insert into testebd (cmixa_id) values (" & rw.Cells(0).Value & ") ", con)
                com.ExecuteNonQuery()
            Next
            con.Close()
    
    
        End Sub
    P.S : lol....in my country the weather is almost always very good for the beach!

  6. #46

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Hi , its work i use this code and a database access:

    Code:
    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
            'comando para obter dados
            'da.SelectCommand.CommandText = sql
            'definir a ligacao
            'da.SelectCommand.Connection = Conn
            'limpar a tabela
            ' dt.Clear()
            'preencher com os dados
            'da.Fill(dt)
    
            ' no caso de quereres inserir na tabela 
            sql = "Insert into back (mixa_id) Values (  ) "
            'definir o comando SQL que vais executar
            cmd.CommandText = sql
            'definir a ligacao
            cmd.Connection = Conn
            'usar o try pra não dar barracada :)
            Try
                'abrir a ligacao
                cmd.Connection.Open()
                'executar a query
                If cmd.ExecuteNonQuery() <> 0 Then
                    ' houve linhas afectas
                    MsgBox("A linha foi inserida 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

    I really appreciate your help. I have learned a lot from your tips, MMock !

    Regards,

    Cachado

  7. #47

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Do you know in insert sql what i need to put in values to insert all the records in field cmixa_id?

    Code:
    "Insert into back (mixa_id) Values ( ? ) "
    Thks,

    Cachado

  8. #48
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    I am not sure. Google something like "sql insert multiple rows". I found this on stack overflow, but I can't vouch for its correctness. Plus it will depend on your SQL provider. Each one may have slightly different syntax.

    But it sounds like things are good now. Glad to hear it.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  9. #49

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    I put this :

    Code:
    sql = "Insert into back (mixa_id) Values (@mixa_id  ) "
    and appear the message:

    Attachment 131789

  10. #50
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Couldn't follow the attachment: Invalid Attachment specified. If you followed a valid link, please notify the administrator.

    I am guessing you need to actually plug something into @mixa_id. You are probably trying to execute "Insert into back (mixa_id) Values (@mixa_id)" instead of "Insert into back (mixa_id) Values (589)", for example. Can you just paste the message instead of the whole image?
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  11. #51

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    this the error:
    Name:  1.png
Views: 239
Size:  9.0 KB

    And yes if i put for example value(589), this value add into the database access.

    Hummmm!

    Regards,

    Cachado

  12. #52
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    yes, that is saying @mixa_id is a required parameter but you didn't give it a value.

    Google this error or something like "assign value to sql parameter" if you need help.

    This is probably it for me for today. Good luck, you are almost there.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  13. #53

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    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;

    1203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057 120581205912060120611206212063
    Last edited by jcachado; Oct 28th, 2015 at 05:07 PM.

  14. #54

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    any suggestions on how to solve?

    I'm almost about to solve my problem!

    Thks a lot,

    Cachado

  15. #55
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Yes you are almost about to solve your problem. I suggested a few posts back that you needed to split each textbox into an an array and loop, then you will be inserting the individual values instead of the whole concatenated string. This is not exactly what you need but pretty close; work on it and get it right. Check the rows inserted when the loop is done to make sure you got them all an didn't insert a row of blanks.

    Code:
            Dim a1 As String() = TextBox1.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
            Dim a2 As String() = TextBox2.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
            Dim a3 As String() = TextBox3.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
    
            Dim insertCmd As String = "INSERT INTO Planos_Hist.sdf (ckpt_id, whse_id) VALUES (@ckpt_id, @whse_id)"
            Dim myCommand As New OdbcCommand(insertCmd, con)
    
            For i As Integer = 0 To a1.Length - 1
                myCommand.Parameters.AddWithValue("@ckpt_id", a1(i))
                myCommand.Parameters.AddWithValue("@whse_id", a2(i))
                ' -- Execute your insert command here.  Keep the connection open for the next loop iteration.
                myCommand.Parameters.Clear()
            Next
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  16. #56

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    I added the code to change the fields but returns the following message:


    Code:
       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
          
    
            Dim a1 As String() = TextBox1.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
            'Dim a2 As String() = TextBox2.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
            'Dim a3 As String() = TextBox3.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
    
            Dim insertCmd As String = "INSERT INTO back (mixa_id) VALUES (@mixa_id)"
            Dim myCommand As New OleDbCommand(insertCmd, Conn)
    
            For i As Integer = 0 To a1.Length - 1
                myCommand.Parameters.AddWithValue("@mixa_id", a1(i))
                ' myCommand.Parameters.AddWithValue("@whse_id", a2(i))
                ' -- Execute your insert command here.  Keep the connection open for the next loop iteration.
                myCommand.Parameters.Clear()
            Next

    Name:  query.png
Views: 251
Size:  14.4 KB

    You are great

    Regards,

    Cachado

  17. #57
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Are you sure you have a table called cmixa in your Access database D:\base_access.accdb? Because Access can't find it.

    Open Access directly, open the database and look at the table names in the db.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  18. #58

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Quote Originally Posted by MMock View Post
    Are you sure you have a table called cmixa in your Access database D:\base_access.accdb? Because Access can't find it.

    Open Access directly, open the database and look at the table names in the db.
    The table name in access is back and is correct in the code insert!!!

    The cmixa is a table from informix to add that values to a textbox1.

  19. #59

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    I am objectively intend to save the data table cmixa(textbox1) for a back table(name of the table) in the Access database!


  20. #60
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    But look at the error message. For some reason it is looking for cmixa. Can you correlate that error message with a line number?

    I will be unavailable for the next hour, so try to address any errors on your own. Use google. Chances are you're not the first person having the problems you are having.

    (We cross-posted but see what you can do on your own until I'm back).
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  21. #61

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    I'm about to give up

  22. #62
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    No, do this instead. Set a breakpoint in the button click event. Then step through each instruction to see where that dialog is being shown. Is it in your exception handler? You can write a handler such that it tells you the line number where the problem is. Giving up now would be pointless, and I'd be very mad at you.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  23. #63

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    So that you understand me well and understand what I want;
    Send the complete code. The first part of the code feeds through the Informix connection to textbox1.

    The second part where the problem exists, has the code to add the data from textbox1 for base_access.accdb(only with the field mixa_id) database where the table was created with the name back

    Code:
    Imports System.Data.Odbc
    Imports System.Data.SqlClient
    Imports System.Configuration
    Imports System.Data.OleDb
    
    
    Public Class teste
    
    
        Private Sub teste_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Dim con As New Odbc.OdbcConnection("Dsn=informix;DATABASE=system;host=exe;serv=onlinet;srvr=onlinet;pro=onsoctcp;uid=test;pwd=pass")
            Dim com As New Odbc.OdbcCommand("SELECT mixa_id from cmixa", con)
            Dim da As New Odbc.OdbcDataAdapter(com)
            Dim dr As Odbc.OdbcDataReader
    
    
    
            con.Open()
            dr = com.ExecuteReader
    
            If dr.HasRows Then
                While dr.Read()
    
                    TextBox1.Text = TextBox1.Text + dr("mixa_id").ToString + Environment.NewLine
    
    
                End While
            End If
    
            dr.Close()
    
            con.Close()
    
    
    
    
        End Sub
    
    
    
    
        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
    
            Dim a1 As String() = TextBox1.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
            'Dim a2 As String() = TextBox2.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
            'Dim a3 As String() = TextBox3.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
    
            Dim insertCmd As String = "INSERT INTO back (mixa_id) VALUES (@mixa_id)"
            Dim myCommand As New OleDbCommand(insertCmd, Conn)
    
            For i As Integer = 0 To a1.Length - 1
                myCommand.Parameters.AddWithValue("@mixa_id", a1(i))
                ' myCommand.Parameters.AddWithValue("@whse_id", a2(i))
                ' -- Execute your insert command here.  Keep the connection open for the next loop iteration.
                myCommand.Parameters.Clear()
            Next
    
    
    
          
            cmd.CommandText = sql
            
            cmd.Connection = Conn
    
    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
                    
                    cmd.Connection.Close()
                End If
            End Try
            
    
        End Sub
    
    
    End Class
    I already put breakpoint mas it seems dont return nothing!

  24. #64
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Please do exactly these steps and tell me what you see.

    1. Open Access and confirm that you absolutely do have a table called mixa_id in database base_access.
    If yes,
    2. Put a breakpoint on Dim Connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\base_access.accdb"
    3. Execute your program and click Button1. Hit the breakpoint. Step through each instruction. I need to know the line you are bombing on. When do you hit F10 and then see the messagebox?

    There is also something else wrong. I wrote a comment TO YOU in English (sorry) to "execute your insert command here." That was telling you, you need to complete the code. Insert needs to go in the loop. But we can deal with that later, after you get your db and table figured out.

    Also, do this. Remove this line from you button1 code: Dim sql As String = "SELECT mixa_id from cmixa". You aren't using the string after you declare it, and it's confusing because it references cmixa.

    You are having far less code problems than you are problems communicating with me because of your English, but hang in there.
    Last edited by MMock; Oct 29th, 2015 at 10:42 AM. Reason: remove stray word
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  25. #65

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Quote Originally Posted by MMock View Post
    Please do exactly these steps and tell me what you see.

    1. Open Access and confirm that you absolutely do have a table called mixa_id in database base_access.
    If yes,
    The table inside the database (Data Source=D:\base_access.accdb) has the name back and not mixa_id , mixa_id is the only field in table back!

    2. Put a breakpoint on Dim Connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\base_access.accdb"
    do it!


    3. Execute your program and click Button1. Hit the breakpoint. Step through each instruction. I need to know the line you are bombing on. When do you hit F10 and then see the messagebox?
    I dont see any relevant message!
    Name:  1.jpg
Views: 166
Size:  23.2 KB

    There is also something else wrong. I wrote a comment TO YOU in English (sorry) to "execute your insert command here." That was telling you, you need to complete the code. Insert needs to go in the loop. But we can deal with that later, after you get your db and table figured out.

    Also, do this. Remove this line from you button1 code: Dim sql As String = "SELECT mixa_id from cmixa". You aren't using the string after you declare it, and it's confusing because it references cmixa.

    You are having far less code problems than you are problems communicating with me because of your English, but hang in there.[/QUOTE]

  26. #66
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Yes, my fault, I misspoke: The table inside the database (Data Source=D:\base_access.accdb) has the name back and not mixa_id , mixa_id is the only field in table back!

    Once you hit your breakpoint, keep going. Hit F10 and it will execute one line at a time and you will hit your error. Maybe a quick tutorial on debugging in Visual Studio would help you. It would be in Spanish and would be easier to understand than I am.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  27. #67

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    You tell me to remove Dim sql As String = "SELECT mixa_id from cmixa" so i need to change the next line and but the insetcmd:

    cmd.CommandText = insertCmd (before sql)

    when i put a breack apeear the message :

    Item = In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.

    I dont no if help or not !!!

  28. #68
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    My fault again. I didn't see where you were using that sql String. Give me a couple minutes and I will try to fix your routine.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  29. #69

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    When i press f10 after the break, still in the code block and not stop, after the next begin again in For i...

    Code:
     
            For i As Integer = 0 To a1.Length - 1
                myCommand.Parameters.AddWithValue("@mixa_id", a1(i))
                ' myCommand.Parameters.AddWithValue("@whse_id", a2(i))
                ' -- Execute your insert command here.  Keep the connection open for the next loop iteration.
                myCommand.Parameters.Clear()
            Next

  30. #70
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Stop until I post again. I think I see the problem.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  31. #71
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Can you replace your button_click event with this and let me know what happens?
    Code:
        Private Sub Button1_Click(ByVal sender As Object, ByVal 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 cmd As New OleDb.OleDbCommand
    
    
            Dim a1 As String() = TextBox1.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
            'Dim a2 As String() = TextBox2.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
            'Dim a3 As String() = TextBox3.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
    
            Dim insertCmd As String = "INSERT INTO back (mixa_id) VALUES (@mixa_id)"
            cmd.CommandText = insertCmd
            cmd.Connection = Conn
            cmd.Connection.Open()
    
            Try
    
                For i As Integer = 0 To a1.Length - 1
                    cmd.Parameters.AddWithValue("@mixa_id", a1(i))
                    'cmd.Parameters.AddWithValue("@whse_id", a2(i))
                    If cmd.ExecuteNonQuery() <> 0 Then
                        Exit For
                    Else
                        MsgBox("ERRO: Os dados não foram inseridos!")
                        Exit Sub
                    End If
    
                    cmd.Parameters.Clear()
                Next
    
                MsgBox("As linhas foram inseridas correctamente na tabela")
    
            Catch ex As Exception
                MsgBox("Exception in Button1_Click():" + ex.Message)
            Finally
                If cmd.Connection.State = ConnectionState.Open Then
                    cmd.Connection.Close()
                End If
            End Try
    
    
        End Sub
    Last edited by MMock; Oct 29th, 2015 at 11:18 AM. Reason: typo
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  32. #72

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Only add one record
    Name:  1.jpg
Views: 149
Size:  8.0 KB

    and have more than one :

    Name:  2.png
Views: 156
Size:  7.6 KB

  33. #73
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Make this one change: If cmd.ExecuteNonQuery() <> 1 Then

    ExecuteNonQuery returns the number of rows affected, so if you do one insert it shouldl return 1.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  34. #74

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Add the same record and next appear the msg in that else:


    Else
    MsgBox("ERRO: Os dados não foram inseridos!")

    Translate: Error: The data were not included.


  35. #75
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Is mixa_id a primary key and you are trying to add a row with a duplicate value?

    Try this, just this once, and if it works we will fix it:
    Code:
                For i As Integer = 1 To a1.Length - 1
    
                    cmd.Parameters.AddWithValue("@mixa_id", a1(i))
    Instead of starting i with value 0 start with 1.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  36. #76

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Add only the second record , 12039, after that show the same error

  37. #77

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    No, mixa_id is not a primary key, the primary key is another field with the name id.

  38. #78
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    I am an idiot. Sorry.

    Code:
            Dim iSuccess As Integer
    
            Try
    
                For i As Integer = 0 To a1.Length - 1
                    cmd.Parameters.AddWithValue("@mixa_id", a1(i))
                    'cmd.Parameters.AddWithValue("@whse_id", a2(i))
                    iSuccess = cmd.ExecuteNonQuery()
                    If iSuccess <> 1 Then
                        MsgBox("ERRO: Os dados não foram inseridos!")
                        Exit Sub
                    End If
    
                    cmd.Parameters.Clear()
                Next
    
                MsgBox("As linhas foram inseridas correctamente na tabela")
    
            Catch ex As Exceptio
    However, you should've caught this. You should take some time and learn how to debug. I had a major logic error which should've been easy to catch. I was getting out of the loop on both a good and a bad DB insert. Stupid.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  39. #79
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: Save results from textbox to sdf table

    Where does this stand? Did that work?
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  40. #80

    Thread Starter
    Addicted Member
    Join Date
    Aug 2015
    Posts
    209

    Re: Save results from textbox to sdf table

    Not yet my friend:

    The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.


    I review the code...

    Thks a lot

    Cachado

Page 2 of 3 FirstFirst 123 LastLast

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