Jump to content

não aparecem os dados inseridos na DataGridView


Recommended Posts

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim cod_lab, cod_responsavel As Integer
        Dim sala, bloco As String
        cod_responsavel = ComboBox1.SelectedItem()
        cod_lab = Label2.Text
        sala = InputBox("Insira a sala pretendida")
        bloco = InputBox("Insira o bloco pretendido")

        'LaboratorioTableAdapter.Adapter.InsertCommand.CommandText = "INSERT INTO laboratorio (cod_lab,sala,bloco,cod_responsavel) VALUES ('" & cod_lab & "','" & sala & "','" & bloco & "','" & cod_responsavel & "')"


        Dim sql = "INSERT INTO laboratorio (cod_lab,sala,bloco,cod_responsavel) VALUES ('" & cod_lab & "','" & sala & "','" & bloco & "','" & cod_responsavel & "')"

        'Dim sql = "INSERT INTO Treinador (cod_lab,sala,bloco,cod_responsavel) VALUES (@cod_lab,@sala,@bloco,@cod_responsavel)"

        Dim cmd As SqlCommand = ligacao.CreateCommand
        'cmd.Parameters.AddWithValue("@cod_lab", TextBox1.Text)
        'cmd.Parameters.AddWithValue("@sala", TextBox2.Text)
        'cmd.Parameters.AddWithValue("@bloco", TextBox3.Text)
        'cmd.Parameters.AddWithValue("@cod_responsavel", TextBox4.Text)

        cmd.CommandText = sql


        MsgBox("Registo Efectuado Com Sucesso", vbInformation)

        form_inserçao_lab.LaboratorioTableAdapter.Adapter.SelectCommand.CommandText = ("Select * from laboratorio")

    End Sub
Link to comment
Share on other sites

está num módulo:

Module Module1
    Public strcon As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\admin\Desktop\Trababalho vb\PAP\PAP\gestor de laboratorios\gestor de laboratorios\gestor.mdf;Integrated Security=True;User Instance=True"
    Public ligacao As New SqlClient.SqlConnection(strcon)
End Module
Link to comment
Share on other sites


penso que no insert , no cod_lab e no cod_responsabel tens aspas simples a mais,

Vê se é isso.



Parecem-me bem, mas o problema duvido que venha daí, porque ele insere bem os dados na base de dados, só não aparecem na DGV por nada deste mundo

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.