Razvanvb Posted February 16, 2016 at 04:11 PM Report Share #593580 Posted February 16, 2016 at 04:11 PM (edited) Boas pessoal. Eu tenho uma datagridview e ao lado tenho um botão para inserir dados. Depois de inseri-los nessa form, eu queria que a tabela (datagridview) atualizasse mal eu inserisse os dados. Será que alguém me pode ajudar? PS: A tabela atualiza depois de eu fechar e abrir o programa, o que eu quero é que atualize na hora! Obrigado! Edited February 16, 2016 at 04:16 PM by Razvanvb Link to comment Share on other sites More sharing options...
Cerzedelo Posted February 16, 2016 at 05:06 PM Report Share #593585 Posted February 16, 2016 at 05:06 PM Se carregar a datagridview através de uma função, basta depois de inserir os dados (ao clicar no botão inserir), chamar essa função e a datagridview e carregada novamente. Link to comment Share on other sites More sharing options...
Razvanvb Posted February 16, 2016 at 05:14 PM Author Report Share #593586 Posted February 16, 2016 at 05:14 PM Se carregar a datagridview através de uma função, basta depois de inserir os dados (ao clicar no botão inserir), chamar essa função e a datagridview e carregada novamente. A datagridview carrega pelo wizard do Visual Basic... Link to comment Share on other sites More sharing options...
Soulsick Posted February 16, 2016 at 05:53 PM Report Share #593591 Posted February 16, 2016 at 05:53 PM Boas, Que data source está atribuído a datagridview? Como estas a gravar? Tens algum código que possas mostrar? Cumps, Link to comment Share on other sites More sharing options...
Razvanvb Posted February 16, 2016 at 06:14 PM Author Report Share #593592 Posted February 16, 2016 at 06:14 PM Boas, Que data source está atribuído a datagridview? Como estas a gravar? Tens algum código que possas mostrar? Cumps, Tinha pelo wizard à bocado, mas meti "unha a unha" como se diz aqui haha. Tenho isto agora: Private Sub Livros_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\311026\Desktop\PAP2\Biblio.accdb" con.Open() datagridshow() End Sub Private Sub datagridshow() Dim ds As New DataSet Dim dt As New DataTable ds.Tables.Add(dt) Dim da As New OleDbDataAdapter da = New OleDbDataAdapter("select * from livrosescola", con) da.Fill(dt) DataGridView1.DataSource = dt.DefaultView con.Close() Link to comment Share on other sites More sharing options...
Soulsick Posted February 16, 2016 at 08:14 PM Report Share #593599 Posted February 16, 2016 at 08:14 PM Boas, então nesse caso depois de guardares o novo registo na base de dados, chamas o método datagridshow(). Só um a parte, passa o con.close() para fora do método, logo depois de chamares datagridshow() no load do form ou entao passas o con.open para dentro do método, assim sabes sempre como andam as ligações à base de dados. Cumps Link to comment Share on other sites More sharing options...
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