Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Alexrafa

Query com duas instruções numa pesquisa

Recommended Posts

Alexrafa

Boas pessoal tou a tentar fazer uma pesquisa com 2 textboxs para dps mostrar num datagrid, mas a query com uma instrução funciona mas com 2 nao, alguem me pode ajudar?

Imports System

Imports System.Data

Imports System.Data.SqlClient

Public Class frmPesquisa

    Inherits System.Windows.Forms.Form

    Private TABELA As [string] = "ALOCACAO"

    Private SALAID As [string] = "SALA_ID"

    Private BLOC As [string] = "BLOCO"

    Private horaf As [string] = "HORA_FIM"

    Private horai As [string] = "HORA_INICIO"

    Private Sub frmPesquisa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       

    End Sub

    Private Sub btnPesquisar2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPesquisar2.Click

       

        'conecta com o banco de dados

        Dim strSql As String = "SELECT * FROM ALOCACAO WHERE SALA_ID= '" + Me.txtSalaP.Text + "'"

        Dim strConexao As String = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\Rafael\Desktop\TrabFC2.3.4\TrabFC\TrabFC\bin\Debug\TFC.mdf';" & ";Integrated Security=True;USER Instance=True"

        Dim da As New SqlDataAdapter(strSql, strConexao)

        Dim dt As New DataTable("ALOCACAO")

        Try

            da.Fill(dt)

            da.FillSchema(dt, SchemaType.Source)

            DataGridView2.DataSource = dt.DefaultView

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

                If txtSalaP.Text.Trim = "" Then

            MessageBox.Show("Informe a sua Sala !", _

                            "SALA_ID", MessageBoxButtons.OK, _

                          MessageBoxIcon.Exclamation)

            txtSalaP.Focus()

            Exit Sub

        End If

        If txtBlocoP.Text.Trim = "" Then

            MessageBox.Show("Informe o seu Bloco !", _

                            "BLOCO", MessageBoxButtons.OK, _

                          MessageBoxIcon.Exclamation)

            txtBlocoP.Focus()

            Exit Sub

        End If

    End Sub

Cumprimentos e obrigado desde ja

Share this post


Link to post
Share on other sites

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

×

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.