Jump to content

[Resolvido] INSERT INTO com problemas


vascoc
 Share

Recommended Posts

Boas, eu tenho estas 2 tabelas ligadas pelos campos:

Tipo_Quatro -------------> ID_Tipo

http://desmond.imageshack.us/Himg715/scaled.php?server=715&filename=semttulobzm.png&res=landing

Ao tentar editar qualquer quarto, mudando o seu tipo aparece-me este erro:

http://img803.imageshack.us/img803/8812/semttulomti.png

Gravar alteração:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If Tipo_QuartoComboBox.Text.Split("|")(1).Trim = lbltp.Text Then
        ErrorProvider1.SetError(Tipo_QuartoComboBox, "Esse é o tipo de quarto atual!")
        Application.DoEvents()
        Thread.Sleep(100) ' Delay
        Tipo_QuartoComboBox.SelectedIndex = -1
        Preco_Tipo_QuartoLabel1.ResetText()
        QuartosDataGridView.Enabled = True
        ErrorProvider1.Clear()
    Else
        Try
            MsgBox("LOL")
            conn = New SqlCeConnection(My.Settings.HOTEL_DBConnectionString)
            cmd = New SqlCeCommand("INSERT INTO Quartos ([Tipo_Quarto]) VALUES ('" & Tipo_QuartoComboBox.Text.Split("|")(0).Trim & "')", conn)
            da = New SqlCeDataAdapter(cmd)
            ds = New DataSet()
            conn.Open()
            Dim dr As SqlCeDataReader = cmd.ExecuteReader
            With conn
                If .State = ConnectionState.Open Then 'ta aberto
                    .Close() ' fechamos
                End If
                ' .Open() ' abrimos a conexao
            End With
            MsgBox("Registo inserido com sucesso !")
            Me.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End If
    conn.Close()
End Sub

Load da minha combobox:

'combo quartos
Private Sub Combo_Quartos()
    Dim S As String = Tipo_QuartoComboBox.Text
    Dim Split() As String = S.Split(Convert.ToChar("|"))
    conn = New SqlCeConnection(My.Settings.HOTEL_DBConnectionString)
    cmd = New SqlCeCommand("SELECT DISTINCT Quartos.Tipo_Quarto, Tipo_Quarto.Tipo_Quarto FROM Tipo_Quarto INNER JOIN Quartos ON Tipo_Quarto.ID_Tipo = Quartos.Tipo_Quarto", conn)
    da = New SqlCeDataAdapter(cmd)
    ds = New DataSet()
    conn.Open()
    Dim dr As SqlCeDataReader = cmd.ExecuteReader
    Tipo_QuartoComboBox.Items.Clear()
    While dr.Read
        Tipo_QuartoComboBox.Items.Add(dr.Item(0) & " | " & dr.Item(1))
'REMOVE O TIPO QUE O QUARTO TEM
        Tipo_QuartoComboBox.Items.Remove(dr.Item(0) & " | " & lbltp.Text)
    End While
    Try
        conn = New SqlCeConnection(My.Settings.HOTEL_DBConnectionString)
        cmd = New SqlCeCommand("Select * from Quartos", conn)
        da = New SqlCeDataAdapter(cmd)
        ds = New DataSet()
        With conn
            If .State = ConnectionState.Open Then
                .Close()
            End If
            .Open()
        End With
        da.Fill(ds, "consulta")
    Catch ex As Exception
        MessageBox.Show(ex.Message, "informação do sistema", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    conn.Close()
End Sub
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
 Share

×
×
  • 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.