Blue_Wings Posted April 27, 2013 at 01:59 AM Report #504986 Posted April 27, 2013 at 01:59 AM (edited) 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 April 27, 2013 at 02:01 AM by Blue_Wings
Blue_Wings Posted April 30, 2013 at 05:49 AM Author Report #505270 Posted April 30, 2013 at 05:49 AM Alguém? Abraços.
Blackvelvet Posted May 1, 2013 at 03:52 PM Report #505467 Posted May 1, 2013 at 03:52 PM (edited) 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 May 1, 2013 at 03:53 PM by Blackvelvet
Blue_Wings Posted May 5, 2013 at 12:33 AM Author Report #505843 Posted May 5, 2013 at 12:33 AM 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?
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