Mr. Henriquez Posted May 18, 2009 at 09:21 AM Report #265010 Posted May 18, 2009 at 09:21 AM Boas, Tenho uma "pequena" dúvida: - Pretendo preencher uma datagridview com dados provenientes de uma base de dados MySql, só que um dos campos tem de ser preenchido com valores provenientes de uma combobox. A datagridview tem de permitir inserir, alterar e eliminar os registos. Existem 2 possiveis soluções. 1 - Preencher a datagridview com um dataAdapter : Dim da As MySqlDataAdapter Dim ds As DataSet Dim sqlQuery As String If conClientMS.State = ConnectionState.Closed Then conClientMS.Open() End If sqlQuery = "SELECT * FROM ENTIDADE_CONTACTO WHERE ID_ENTIDADE ='" & Me.ID_ENTIDADE.Text & "'" da = New MySqlDataAdapter(sqlQuery, conClientMS) ds = New DataSet da.Fill(ds, "myTable") Me.entDataGrid.DataSource = ds.Tables("myTable") conClientMS.Close() Mas neste caso não sei como alterar o campo pretendido de textbox para combobox. 2 - Inserir as colunas que pretendo no datagridview, resolvendo o problema da combobox, mas como é que insiro os dados da base de dados nas celulas?! Dim myData As MySqlDataAdapter Dim myDataSet As DataSet Dim mySqlString As String Dim myDataReader As MySqlDataReader Dim mymCommand As New MySqlCommand If conClientMS.State = ConnectionState.Closed Then conClientMS.Open() End If mySqlString = "SELECT ID_CONTACTO, ID_ENTIDADE, NOME, TELEFONE, FAX, EMAIL, ESTADO FROM ENTIDADE_CONTACTO" mymCommand.CommandText = mySqlString mymCommand.Connection = conClientMS myDataReader = mymCommand.ExecuteReader While myDataReader.Read() Me.entDataGrid.Rows.Add() 'Me.entDataGrid.Columns(0).CellTemplate.Value = myDataReader.Item("ID_ENTIDADE") 'If Not IsDBNull(myDataReader.Item("ID_ENTIDADE")) Then Me.entDataGrid.Item(0 = myDataReader.Item("ID_ENTIDADE") End While Estou a ficar um pouco confuso, porque já procurei vezes sem conta, uma solução na internet e não encontro. Help ME!!! Cumps
vasco16 Posted May 18, 2009 at 11:59 AM Report #265040 Posted May 18, 2009 at 11:59 AM vê se isto ajuda: http://www.portugal-a-programar.pt/index.php?showtopic=27365
Mr. Henriquez Posted May 19, 2009 at 10:21 AM Author Report #265318 Posted May 19, 2009 at 10:21 AM vê se isto ajuda: http://www.portugal-a-programar.pt/index.php?showtopic=27365 Bom dia, Obrigado, mas pelo que vi os tópicos são em linguagem em ASP.Net Qualquer das formas já consegui contornar o meu problema através de um tópico que encontrei neste forum! Obrigado na mesma!
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