我的数据库不显示0的任何值

时间:2014-11-19 10:33:03

标签: mysql database visual-studio-2012 xampp

我有我的数据库XAMPP MySQL,我从Visual Studio 2012中输入值。

我有INSERT INTO mytable的代码,但我总是插入值,此值显示为0。 我不知道原因,因为如果我连接到数据库并发送值,表格通常会显示我写的值。
有人知道问题???

Imports MySql.Data.MySqlClient
Imports MySql.Data
Imports System.Data

Public Class Form1
    Dim Posto_1 As Integer
    Dim Posto_2 As Integer
    Dim Posto_3 As Integer
    Dim Posto_4 As Integer
    Dim Ip_Address As Integer

    Dim myConnectionString As String = "SERVER=127.0.0.1; DATABASE=base_de_dados; UID=root; PASSWORD=123;"

    Private Sub inserir_Click(sender As Object, e As EventArgs) Handles inserir.Click
        Dim insert_bd As String = "INSERT INTO linha(endereco_ip, t_paragem_1, t_paragem_2, t_paragem_3, t_paragem_4) VALUES ('@endereco_ip', '@t_paragem_1', '@t_paragem_2', '@t_paragem_3', '@t_paragem_4');"
        Dim connection As New MySqlConnection(myConnectionString)
        Dim command As New MySqlCommand(insert_bd, connection)

        If (posto1Text.Text = "" Or posto2Text.Text = "" Or posto3Text.Text = "" Or posto4Text.Text = "" Or ipText.Text = "") Then
            MessageBox.Show("Não foi inserido nenhum valor")
        Else
            Ip_Address = CInt(ipText.Text)
            Posto_1 = CInt(posto1Text.Text)
            Posto_2 = CInt(posto2Text.Text)
            Posto_3 = CInt(posto3Text.Text)
            Posto_4 = CInt(posto4Text.Text)

            Try
                connection.Open()
                ListBox1.Items.Add("Base de Dados --> Escrever. . .")
                command.Parameters.AddWithValue("@endereco_ip", Ip_Address)
                command.Parameters.AddWithValue("@t_paragem_1", Posto_1)
                command.Parameters.AddWithValue("@t_paragem_2", Posto_2)
                command.Parameters.AddWithValue("@t_paragem_3", Posto_3)
                command.Parameters.AddWithValue("@t_paragem_4", Posto_4)
                command.ExecuteNonQuery()
            Catch ex As Exception
                MessageBox.Show("Erro de ligação", "AVISO!!!")
            End Try

            connection.Close()
            connection = Nothing
            command = Nothing
        End If
    End Sub

0 个答案:

没有答案
相关问题