Author Topic: Array value  (Read 8083 times)

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Array value
« Reply #30 on: June 17, 2018, 11:13:35 AM »
If your code works once only then try moving it to a sub like this:

Code: [Select]
    Private Sub BasicLabel4_ValueChanged(sender As Object, e As EventArgs) Handles BasicLabel4.ValueChanged
        Dim MysqlConn As MySqlConnection
        Dim COMMAND As MySqlCommand

        MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString =
        "server=localhost;userid=root;password=;database=technique"
        Dim READER As MySqlDataReader
        Try
            MysqlConn.Open()
            Dim Query As String

            Query = "insert into technique.DATA (id,value) values ('" & 0 & "' , '" & BasicLabel4.Value & "')"
            COMMAND = New MySqlCommand(Query, MysqlConn)
            READER = COMMAND.ExecuteReader
        Catch ex As Exception
            MysqlConn.Close()
        End Try
    End Sub

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #31 on: June 17, 2018, 12:44:13 PM »
thank you friends
The connection to mysql is not stable and sometimes it does not work without any warning.
I need to store the data in a SQL SERVER database via DataSubscriber.

@Godra, i try to use ta.Fill(t)
the error message is gone but the function did not work
no error message and no record in the database.

Phrog30

  • Guest
Re: Array value
« Reply #32 on: June 17, 2018, 01:14:49 PM »
In have used MySQL a bunch, it's not unstable in the least. You are doing something wrong. One post you stated you get only 100 values but you showed insert statement, so how are you seeing the data, within MySQL?

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #33 on: June 17, 2018, 01:29:53 PM »
data storage is working properly, up to line number 100 (id = 100 "AUTO_INCREMENT")
the application stops working (the main form application)  => become unresponsive
and no new registration in the database
every time in line number 100

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #34 on: June 17, 2018, 02:06:52 PM »
i use the value as 0 in order to test the program
but the same problem
« Last Edit: June 17, 2018, 02:09:31 PM by MEDALI1TN »

Phrog30

  • Guest
Re: Array value
« Reply #35 on: June 17, 2018, 05:17:24 PM »
I think you are doing the database stuff completely backwards.  Forget Visual Studio.  Matter of fact, close the application.  You need to learn the DB side first, regardless if you use SQL, MySQL, etc.  Since it looks like you have gotten farther in MySQL, I would use that.  You can run queries straight from the workbench.  So, run your own insert statements, learn how to do select statements, etc.  Then once you have the DB working, you simply copy the queries and paste in VS.  Your form being unresponsive most likely has nothing to do with MySQL, rather your code in VS.  Running a transaction with only 100 rows should take almost no time at all.  You shouldn't notice the UI lock up at all.  For giggles, run a select * in workbench, it will tell you how long it takes.  It's probably so fast it will say 0.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #36 on: June 18, 2018, 03:45:46 AM »
I tried sql alone: it works
and the application without queries works properly and especially without blocking (never)
only if I use the database, and exactly when the ID reaches line number 100 !!!


MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #37 on: June 18, 2018, 04:53:38 AM »
I put all the code in comment and I activated only the request.
the same thing, when the ID reaches line number 100 the application crashes.
I think there is a limit in the base (limit in the number of lines).
because if I restart the application without initializing the counter, it will appear a line that makes the separation between the value 100 and 101.

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Array value
« Reply #38 on: June 18, 2018, 06:59:01 AM »
I don't know if this might work but it doesn't hurt to try:

Code: [Select]
    Private Sub DataSubscriber1_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataReturned
        Dim conString As String = "server=localhost;userid=root;password=;database=technique"
        Using con As New MySqlConnection(conString)
            Using cmd As New MySqlCommand("insert into technique.DATA (id,value) values ('" & 0 & "' , '" & e.Values(0) & "')", con)
                cmd.CommandType = CommandType.Text
                Using sda As New MySqlDataAdapter(cmd)
                    Using dt As New DataTable()
                        sda.Fill(dt)
                    End Using
                End Using
            End Using
        End Using
    End Sub


The code was adopted from here:

https://www.aspsnippets.com/Articles/Fill-Populate-DataTable-using-MySqlDataAdapter-in-C-and-VBNet.aspx


If it might need to use your settings then it would look like this:

Code: [Select]
    Private Sub DataSubscriber1_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataReturned
        Dim conString As String = "server=localhost;userid=root;password=;database=technique"
        Using con As New MySqlConnection(conString)
            Using cmd As New MySqlCommand("insert into technique.DATA (id,value) values ('" & 0 & "' , '" & e.Values(0) & "')", con)
                cmd.CommandType = CommandType.Text
                Using sda As New techniqueDataSetTableAdapters.DATATableAdapter(cmd)
                    Using dt As New techniqueDataSet.DATADataTable()
                        sda.Fill(dt)
                    End Using
                End Using
            End Using
        End Using
    End Sub

« Last Edit: June 18, 2018, 07:06:56 AM by Godra »

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #39 on: June 18, 2018, 07:55:51 AM »
Thank you friend.
Unfortunately it did not work  :(
I think that with "DataSubscriber1_DataReturned" he wants to connect to SQLSERVER and not MySQL.
the program looking for user 'sa'

Phrog30

  • Guest
Re: Array value
« Reply #40 on: June 18, 2018, 08:35:05 AM »
Are you trying to insert at specific IDs? I would create the table with auto increment and unique IDs. Let the database do all of the work. If you are only wanting 100 rows and those get updated, then I probably wouldn't even use a database.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #41 on: June 18, 2018, 09:05:25 AM »
i use already the auto increment id.
I already need a few thousand lines a day
I want to read the current absorbed by the machines instantly

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
    • View Profile
    • AdvancedHMI
Re: Array value
« Reply #42 on: June 18, 2018, 09:51:54 AM »
I have not been able to fully keep up with this topic and only have a few minutes to respond, so I want to quickly clarify a few things about data sources. The Data Source is a Visual Studio tool that creates classes that maps to tables, View, and Procedures of a database. When you create a Data Source, you tell it what type of data base and how to connect to it. The Table Adapters contain the mechanisms to move data in and out of a data base. The Fill method is a read command while an Update is a write command. The Data Tables are the objects that hold the actual data in memory from the database. When you call Fill, it reads from the database and transfers the values to a Data Table. When you call Update, it transfers the changes made to the Data Table back to the data base.

Once you define a Data Source, it is dedicated to the database you defines. For example, if you create a data source for a SQL Server, it will not communicate to MySQL without major changes. If you want to change databases, you are better off to create a new Data Source.

The Data Source is just a tool to reduce the amount of code necessary for database interaction. They are not necessary to use. You can use raw ADO.NET and manually write the code.

Phrog30

  • Guest
Re: Array value
« Reply #43 on: June 18, 2018, 09:58:01 AM »
i use already the auto increment id.
I already need a few thousand lines a day
I want to read the current absorbed by the machines instantly

But, it looks like your insert statement is setting an ID. You don't set the id, you let the database do that.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Array value
« Reply #44 on: June 19, 2018, 08:32:46 AM »
I did more than 1000 test but without success...
I thank you all friends for your help..
« Last Edit: June 19, 2018, 08:36:00 AM by MEDALI1TN »