Jump to content

Recommended Posts

Posted (edited)

Amigos tenho mais uma duvida. Tenho um select que é feito no banco de dados e retorna os dados no datagrid. O problema é que não sei qual é a melhor forma de fazer isso. Mas consegui fazer da forma abaixo. Porem se perceber no código tem 2 linha comentadas que funcionam a consulta porem a terceira dá erro : SqlException was unhndled (The identifier that stars with) as Categoria, count

Preciso saber como fazer esse código funcionar e qual é a melhor maneira de escrever comando sql no vb.

Private Sub BT_pesquisar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_pesquisar.Click
	'Conexão com o banco.
	conexao.ConnectionString = "Data Source=172.20.6.125,3433;Initial Catalog=DBSQUALITOR_CPT_PRD;User ID=loginNome;Password=******"
	'OS DOIS CÓDIGO ABAIXO QUE ESTÃO COMENTADO ESTÃO FUNCIONANDO RETORNANDO PARA O MEU GRID A CONSULTA. POREM O TERCEIRO NÃO.
	'Dim da As New SqlDataAdapter("select D.nmequipe as Equipe, COUNT(*) as Qtd_Usuarios from ad_usuarioconcorrente A left join ad_usuario B on A.cdusuario=B.cdusuario left join hd_equipepreferencial C on B.cdusuario=C.cdusuario left join hd_equipe D on C.cdequipe=D.cdequipe GROUP BY D.nmequipe order by 1", conexao)
	'Dim da As New SqlDataAdapter("select * from hd_chamado where cdcategoria in ('" & txtPesquisar.Text & "') and dttermino between '" & DT_inicial.Text & "'and '" & DT_final.Text & "'", conexao)
	Dim da As New SqlDataAdapter("SELECT (select nmcategoria from hd_categoria where cdcategoria='" & txtPesquisar.Text & "'"") as Categoria, count (A.cdchamado) as Chamados FROM hd_chamado A INNER JOIN hd_categoria B ON A.cdcategoria=B.cdcategoria where dttermino between '" & DT_inicial.Text & "' and '" & DT_final.Text & "' and A.cdcategoria in ( SELECT cdcategoria FROM ( SELECT * FROM hd_categoria WHERE cdcategoria = '" & txtPesquisar.Text & "'"" UNION SELECT * FROM hd_categoria WHERE cdcategoriasuperior = '" & txtPesquisar.Text & "'"" UNION SELECT * FROM hd_categoria WHERE cdcategoriasuperior IN ( SELECT cdcategoria FROM hd_categoria WHERE cdcategoriasuperior = '" & txtPesquisar.Text & "'"" ) ) AS QRY )", conexao)

	Dim ds As New DataSet
	'Pega os dados do DataSet e joga no Hd_chamadoDataGridView
	da.Fill(ds)
	Me.Hd_chamadoDataGridView.DataSource = ds.Tables(0).DefaultView
	Hd_chamadoDataGridView.Columns(0).Width = 300
End Sub
Edited by williamjda

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
×
×
  • Create New...

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.