Member 12919322
Хорошо, спасибо за ответ, но я думаю, что что-то не так с mysql, у меня есть следующая ошибка.
Данные усечены для colum 'Precio_Sin_Iva' в строке 1.
Может быть, поставить весь код помощи лучше :
Imports MySql.Data.MySqlClient
Imports System.Configuration
Imports System.Resources
Imports System.Decimal
Public Class CosteMaquinaria
Dim MysqlConn As MySqlConnection
Dim COMMAND As MySqlCommand
Dim READER As MySqlDataReader
Dim a As New OpenFileDialog
Dim dr As MySqlDataReader
Private Sub CosteMaquinaria_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox9.Text = "21,00"
MysqlConn = New MySqlConnection(ConfigurationManager.ConnectionStrings("test").ToString)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MysqlConn.Close()
MysqlConn.Open()
MysqlConn = New MySqlConnection(ConfigurationManager.ConnectionStrings("test").ToString)
Me.Cursor = Cursors.WaitCursor
Dim SDA As New MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource
Try
MysqlConn.Close()
MysqlConn.Open()
Dim Query As String
Query = "select Numero_Interno,Matricula,Marca,Numero_Serie,Modelo,Tipo_Maquinaria from xCantera.Flota"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
DataGridView1.DataSource = bSource
DataGridView1.Columns("Tipo_Maquinaria").Visible = False
SDA.Update(dbDataSet)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
Me.Cursor = Cursors.Default
End Sub
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
TextBox1.Text = row.Cells("Numero_Interno").Value.ToString
TextBox2.Text = row.Cells("Matricula").Value.ToString
TextBox3.Text = row.Cells("Marca").Value.ToString
TextBox4.Text = row.Cells("Numero_Serie").Value.ToString
TextBox5.Text = row.Cells("Modelo").Value.ToString
TextBox6.Text = row.Cells("Tipo_Maquinaria").Value.ToString
End If
'Seleccion Combobox1
Try
MysqlConn.Open()
Dim Query As String
Query = "select Categorias from xCantera.CostesMaquinaria_SubGrupos where Tipo_Maquinaria = '" & TextBox6.Text & "' ORDER BY Categorias ASC"
COMMAND = New MySqlCommand(Query, MysqlConn)
READER = COMMAND.ExecuteReader
'Reinicio Combo
ComboBox1.Items.Clear()
'TextBox1.Clear()
While READER.Read
ComboBox1.Items.Add(READER.GetString("Categorias"))
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
'Seleccion Combobox1
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0 ' The first item has index 0 '
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
End Sub
Private Sub TextBox10_TextChanged(sender As Object, e As EventArgs) Handles TextBox10.TextChanged
End Sub
Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles TextBox8.TextChanged
' Calcular Precio Final Con IVA
Dim Sin_IVA, IVA, Total_IVA As Decimal
Sin_IVA = TextBox8.Text
IVA = TextBox9.Text
Total_IVA = ((Sin_IVA * IVA) / 100) + Sin_IVA
TextBox10.Text = Total_IVA.ToString
TextBox11.Text = Total_IVA - Sin_IVA
End Sub
Private Sub TextBox9_TextChanged(sender As Object, e As EventArgs) Handles TextBox9.TextChanged
'' Calcular Precio Final Con IVA
'Dim Sin_IVA, IVA, Total_IVA As Decimal
'Sin_IVA = Val(TextBox8.Text)
'IVA = Val(TextBox9.Text)
'Total_IVA = ((Val(Sin_IVA) * Val(IVA)) / 100) + Val(Sin_IVA)
'TextBox10.Text = Total_IVA.ToString
'' Calcular Precio Final Con IVA
'' Calcular dif Precio Final Con IVA
'TextBox11.Text = Val(Total_IVA) - Val(Sin_IVA)
'' Calcular dif Precio Final Con IVA
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Insertar en Base de Datos
Me.Cursor = Cursors.WaitCursor
'Dim MysqlConn As MySqlConnection
Dim Sin_IVA, Con_IVA, Diff_IVA As Decimal
Sin_IVA = Val(TextBox8.Text)
Con_IVA = Val(TextBox10.Text)
Diff_IVA = Val(TextBox11.Text)
Dim COMMAND As New MySqlCommand
Dim READER As MySqlDataReader
Dim a As New OpenFileDialog
Try
MysqlConn.Open()
COMMAND.Connection = MysqlConn
COMMAND.CommandText = "INSERT INTO CostesMaquinaria (Numero_Interno, Grupo_Gastos, Numero_Factura, Precio_Sin_Iva, IVA, Precio_Con_Iva, Diff_IVA)
Values(@Value1,@Value2,@Value3,@Value4,@Value5,@Value6,@Value7)"
COMMAND.Parameters.AddWithValue("@Value1", TextBox1.Text)
COMMAND.Parameters.AddWithValue("@Value2", ComboBox1.Text)
COMMAND.Parameters.AddWithValue("@Value3", TextBox7.Text)
COMMAND.Parameters.AddWithValue("@Value4", TextBox8.Text)
COMMAND.Parameters.AddWithValue("@Value5", TextBox9.Text)
COMMAND.Parameters.AddWithValue("@Value6", TextBox10.Text)
COMMAND.Parameters.AddWithValue("@Value7", TextBox11.Text)
READER = COMMAND.ExecuteReader
MsgBox("Data Save !", MsgBoxStyle.Information)
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
Me.Cursor = Cursors.Default
End Sub
End Class
Мой объект DataTable являются последующие :
CREATE TABLE IF NOT EXISTS `CostesMaquinaria` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Numero_Interno` varchar(255) DEFAULT NULL,
`Grupo_Gastos` varchar(255) DEFAULT NULL,
`Numero_Factura` varchar(255) DEFAULT NULL,
`Precio_Sin_Iva` decimal(10,3) DEFAULT NULL,
`IVA` decimal(10,3) DEFAULT NULL,
`Precio_Con_Iva` decimal(10,3) DEFAULT NULL,
`Diff_IVA` decimal(10,3) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;