Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
Blue_Wings

Botão "Save" não guarda na DB todas as alterações das Textbox

Recommended Posts

Blue_Wings

Boa noite,

Tenho várias TextBox com dados de uma tabela de access, e tenho este código no botão que me vai guardar os dados com Save_Records()


Private Sub Save_Records()
 With Me.BindingContext(Me.Uniforms_SoftwareDataSet, "BLAZER_DARK")
	 .EndCurrentEdit()
	 If Uniforms_SoftwareDataSet.HasChanges Then
		 Try
			 If MsgBox("Record has changer!" & vbCrLf & "Save changes?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2) = MsgBoxResult.Yes Then
				 Me.BLAZER_DARKTableAdapter.Update(Uniforms_SoftwareDataSet.GetChanges())
				 Uniforms_SoftwareDataSet.AcceptChanges()
			 Else
				 Uniforms_SoftwareDataSet.RejectChanges()
			 End If
		 Catch ex As Exception
			 MsgBox(ex.Message)
		 End Try
	 End If
 End With
 With Me.BindingContext(Me.Uniforms_SoftwareDataSet, "BLAZER_BLUE")
	 .EndCurrentEdit()
	 If Uniforms_SoftwareDataSet.HasChanges Then
		 Try
			 If MsgBox("Record has changer!" & vbCrLf & "Save changes?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2) = MsgBoxResult.Yes Then
				 Me.BLAZER_BLUETableAdapter.Update(Uniforms_SoftwareDataSet.GetChanges())
				 Uniforms_SoftwareDataSet.AcceptChanges()
			 Else
				 Uniforms_SoftwareDataSet.RejectChanges()
			 End If
		 Catch ex As Exception
			 MsgBox(ex.Message)
		 End Try
	 End If
 End With
 With Me.BindingContext(Me.Uniforms_SoftwareDataSet, "TROUSERS")
	 .EndCurrentEdit()
	 If Uniforms_SoftwareDataSet.HasChanges Then
		 Try
			 If MsgBox("Record has changer!" & vbCrLf & "Save changes?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2) = MsgBoxResult.Yes Then
				 Me.TROUSERSTableAdapter.Update(Uniforms_SoftwareDataSet.GetChanges())
				 Uniforms_SoftwareDataSet.AcceptChanges()
			 Else
				 Uniforms_SoftwareDataSet.RejectChanges()
			 End If
		 Catch ex As Exception
			 MsgBox(ex.Message)
		 End Try
	 End If
 End With
 With Me.BindingContext(Me.Uniforms_SoftwareDataSet, "WHITE_SHIRT_SHORT_SLEEVE")
	 .EndCurrentEdit()
	 If Uniforms_SoftwareDataSet.HasChanges Then
		 Try
			 If MsgBox("Record has changer!" & vbCrLf & "Save changes?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2) = MsgBoxResult.Yes Then
				 Me.WHITE_SHIRT_SHORT_SLEEVETableAdapter.Update(Uniforms_SoftwareDataSet.GetChanges())
				 Uniforms_SoftwareDataSet.AcceptChanges()
			 Else
				 Uniforms_SoftwareDataSet.RejectChanges()
			 End If
		 Catch ex As Exception
			 MsgBox(ex.Message)
		 End Try
	 End If
 End With
End Sub

Depois de ter modificado os dados de várias textbox quando clico no botão para guardar, apenas guarda os dados da primeira textbox, das textbox´s seguintes só guarda se eu clicar na própria textbox e voltar a clicar no botão de guardar dados.

Não era suposto clicar só uma vez no botão e ir a todas as texbox e ver se existe alterações e guardar tudo de uma só vez?

:)

Edited by Blue_Wings

Share this post


Link to post
Share on other sites
Blackvelvet

Eu faço sempre assim:

 'coneção á base de dados
		Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog="nome_tabela";Integrated Security=SSPI;")
		Dim SQL As String
		SQL = "SELECT * FROM registo WHERE ID = '" & Tabela.id_pesquisa & "'"
		Dim command As New SqlCommand(SQL, connection)
		connection.Open()
		Dim dataAdapter As New SqlDataAdapter(command)
		Dim Data As New DataTable
		dataAdapter.Fill(Data)
		txtalgo.Text = Data.Rows(0)(0)
	  ' sempre definindo as caixas de texto e gravar na respectica linha/coluna

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

Edited by Blackvelvet

Share this post


Link to post
Share on other sites
Blue_Wings

Alguém me pode dizer o que está errado no meu código para ele não estar a gravar as textbox todas de uma só vez quando eu carrego no botão que vai buscar o código de Save_Records() ?

Está errado usar databinding para cada uma das tabelas na base de dados?

Share this post


Link to post
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
Sign in to follow this  

×

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.