Jump to content

[Resolvido] Erros


vascoc
 Share

Recommended Posts

Boas, eu tenho este form que faz uma reserva e adiciona extras, etc.... Mas como podem ver tenho vários erros, passo a descrever em baixo com código:

http://img696.imageshack.us/img696/8360/dddqn.png

Erro da Datagrid em runtime :

Os extras que são mostrados na datagrid só deveriam de ser do Cod_Reserva actual, neste caso o número 43, e claro, caso houvesse já algum extra adicionado.

BOTÃO ONDE GRAVA OS EXTRAS

 Private Sub cmdgravarextra_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdgravarextra.Click
	If horascombo.Text = "" Or Cod_ExtrasComboBox.Text = "" Then
		MsgBox("Preencha os campos!", MsgBoxStyle.Critical)
		Else

			Try
				conn = New SqlCeConnection(My.Settings.HOTEL_DBConnectionString)
				cmd = New SqlCeCommand("Select * FROM Reserva_Extra", conn)
				da = New SqlCeDataAdapter(cmd)
				ds = New DataSet()

				With conn
					If .State = ConnectionState.Open Then 'ta aberto
						.Close() ' fechamos

					End If
					.Open() ' abrimos a conexao
				End With
				da.Fill(ds, "consulta")
				cb = New SqlCeCommandBuilder(da)
			Catch ex As Exception
				MessageBox.Show(ex.Message, "informação do Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error)
			End Try
			a = MessageBox.Show("Tem a certeza que pertende inserir o registo selecionado?", "Inserir", MessageBoxButtons.OKCancel)
			If a = MsgBoxResult.Ok Then
				tr = ds.Tables("consulta").Rows.Count
				Dim dsnewrow As DataRow

				dsnewrow = ds.Tables("consulta").NewRow()
				dsnewrow.Item("Cod_Reserva") = Cod_ReservaLabel1.Text
				dsnewrow.Item("Data_Extra") = lbldia.Text
				dsnewrow.Item("Cod_Extra") = Cod_ExtrasComboBox.Text.Split("|")(0).Trim
				dsnewrow.Item("hora_extra") = horascombo.Text
				ds.Tables("consulta").Rows.Add(dsnewrow)
				da.Update(ds, "consulta")

				MessageBox.Show("Registo inserido com sucesso.", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
				conn.Close()
			datagridextras()
			Cod_ExtrasComboBox.Visible = False
			cmdgravarextra.Visible = False
			End If
		End If

End Sub

DATAGRID

Public Sub datagridextras()
	sql1 = "Select Data_Extra, Cod_Extra, Hora_extra FROM Reserva_Extra WHERE Cod_Reserva =" & Cod_ReservaLabel1.Text & ""
	procura_extras_reserva()
		If total = 0 Then
			MessageBox.Show("Nenhum registo encontrado")
		Else
			For i As Integer = Me.Controls.Count - 1 To 0 Step -1
				If TypeOf Me.Controls(i) Is DataGrid Then
					Me.Controls.RemoveAt(i)
				End If
			Next
			dg = New DataGrid()
		dg.Location = New Point(100, 200)
			dg.ReadOnly = True
			dg.Refresh()
			'ajustar da tabela
			dg.Dock = DockStyle.None
			dg.BorderStyle = BorderStyle.FixedSingle
		dg.Size = New System.Drawing.Size(340, 300)
			dg.CaptionVisible = False
			Me.Controls.Add(dg)
			dg.SetDataBinding(ds, "Consulta")
			'dg.Enabled = False
		dg.Update()
		End If
End Sub

Public Sub procura_extras_reserva()
	Try
		conn = New SqlCeConnection(My.Settings.HOTEL_DBConnectionString)
		cmd = New SqlCeCommand(sql1, 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
	total = ds.Tables("consulta").Rows.Count
End Sub
Edited by Caça
GeSHi
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.