ricardom94 Posted April 9, 2012 at 02:02 PM Report #448204 Posted April 9, 2012 at 02:02 PM Eu tenho o mesmo erro o programa diz me que se ligou a bd mas quando vou a inserir um registo ele dame erro no mesmo sitio Imports MySql.Data.MySqlClient Public Class Form1 Dim serverstring As String = "Server=localhost;Userid=root;Password=;Database=test" Dim sqlcon As MySqlConnection = New MySqlConnection Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sqlcon As MySqlConnection = New MySqlConnection sqlcon.ConnectionString = serverstring Try If sqlcon.State = ConnectionState.Closed Then sqlcon.Open() MsgBox("Ele diz que se ligou a bd") Else sqlcon.Close() MsgBox("Ele diz que nao se ligou a bd") End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Public Sub inserir(ByRef sqlstatement As String) Dim cmd As MySqlCommand = New MySqlCommand(sqlstatement, sqlcon) With cmd .CommandText = sqlstatement .CommandType = CommandType.Text .Connection = sqlcon .ExecuteNonQuery() End With sqlcon.Close() MsgBox("Ele diz que inseriu") sqlcon.Dispose() End Sub Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click Dim sqlstatement As String = "INSERT INTO tt(krl) VALUES('" & cod.Text & "')" inserir(sqlstatement) End Sub e depois diz me isto do executenonquery http://img696.imageshack.us/img696/2053/erroks.png agradecia alguma dica sff
ricardom94 Posted April 9, 2012 at 02:32 PM Author Report #448215 Posted April 9, 2012 at 02:32 PM Resolvido 👍
José Lopes Posted April 9, 2012 at 02:34 PM Report #448216 Posted April 9, 2012 at 02:34 PM Eu ia sugerir que testasses a conexão antes de cada inserção.... E obviamente fechá-a no final ;-) Quando te pedirem peixe.... ensina-os a Pescar!!Hum..lálálálá!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now