whize13 Posted June 18, 2014 at 02:28 PM Report Share #559614 Posted June 18, 2014 at 02:28 PM Gostava de saber como posso preencher cada coluna da GV com os valores devolvidos das queries é algo haver com isto? http://forums.asp.net/t/1202927.aspx? http://forums.asp.net/t/1202927.aspx?fill+datagrid+from+database+using+Data+table+and+Data+set+using+asp+net+with+vb+code Link to comment Share on other sites More sharing options...
whize13 Posted June 18, 2014 at 03:17 PM Author Report Share #559624 Posted June 18, 2014 at 03:17 PM (edited) Classe.ligacao.Open() Try Dim queryCodDisciplina As New SqlCommand("SELECT CodDis FROM Disciplinas WHERE DesignacaoDis ='" & DDLDisciplinas.Text & "'", Classe.ligacao) Dim CodDis As Integer = queryCodDisciplina.ExecuteScalar Dim ad As New SqlDataAdapter ad.SelectCommand = New SqlCommand("SELECT Licao, Sumario, DataSumario, DataRegisto FROM RegistoDia WHERE CodProf ='" & Session("CodProf").ToString & "' and CodDis = '" & CodDis & "' and IDTurma ='" & Session("IDTurma").ToString & "'", Classe.ligacao) Dim ds As New DataSet ad.Fill(ds) GVSumario.DataSource = ds GVSumario.DataBind() Classe.ligacao.Close() Catch ex As Exception MsgBox(ex.Message) End Try Panel1.Visible = True GVSumario.Visible = True Pronto, eu exprimentei o codigo e ficou assim o problema é a GridView não está visivel Edited June 18, 2014 at 03:17 PM by whize13 Link to comment Share on other sites More sharing options...
whize13 Posted June 20, 2014 at 03:02 PM Author Report Share #559865 Posted June 20, 2014 at 03:02 PM ja tive a testar e este metodo nao funciona, preciso mesmo de ajuda Link to comment Share on other sites More sharing options...
IvorY Posted July 8, 2014 at 09:42 AM Report Share #561817 Posted July 8, 2014 at 09:42 AM Não sei se ainda precisas de ajuda, mas eu também não consegui fazer com este método. Em SQL Server, se usar só um DataReader, fica operacional, com OracleDB, não chega. Deixo aqui dois exemplos que funcionam bem para mim. SQL Server using (SqlConnection conn = new SqlConnection(connectionString)) { string query = @"select ID, first_name, last_name, age, class from Persons with (NOLOCK) where sex = "+auditNumber+@"; select * from Department where name='open'; select * from Persons with(NOLOCK) inner join Jobs on Persons.work = Jobs.work_id where sex = "+auditNumber+@""; SqlCommand command = new SqlCommand(query, conn); SqlDataReader reader = null; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("sex", SqlDbType.Bit).Value = auditNumber; try { if (conn.State == ConnectionState.Closed) { conn.Open(); } reader = command.ExecuteReader(); //para cada grid aloca datasource e faz databind. GridView1.DataSource = reader; GridView1.DataBind(); //passa ao proximo select reader.NextResult(); GridView2.DataSource = reader; GridView2.DataBind(); mainView.SetActiveView(boxView); lblError.Text = "Concluída a extração de informação da Base de Dados. Timestamp: " + DateTime.Now; } catch (SqlException ex) { lblError.Text = "Erro de SQL: " + ex.ToString(); } finally { conn.Close(); } } OracleDB OracleCommand command = new OracleCommand(query,conn); OracleCommand command2 = null; OracleDataReader reader = null; DataTable dt = new DataTable(); command.CommandType = CommandType.Text; try { conn.Open(); reader = command.ExecuteReader(); dt.Load(reader); GridView1.DataSource = dt; GridView1.DataBind(); reader.Close(); conn.Close(); } catch (OracleException ex) { lblError.Text = "Erro de OracleSQL: " + ex.ToString(); } No caso de OracleDB vi-me obrigado a fazer uma DataTable por cada grid que queria preencher, ainda não descobri porquê. Mas a verdade é que isto funciona, apesar de ser à lei do martelo. 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