Jump to content

Consultar Bases de Dados no VB


Recommended Posts


se consegues ver os campos no dgv

é so fazeres assim

Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
txtbox.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value.ToString()

Cells(1) é o numero da coluna



Link to comment
Share on other sites

esta me a dar um erro:

 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim ConnectionString As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\baseteste.mdb")
        Dim query As String = "SELECT * FROM Login WHERE User = @User"

        Dim command As New OleDbCommand(query, ConnectionString)
        command.Parameters.Add("@User", OleDbType.VarChar).Value = TextBox1.Text

        Dim DataAdapter As New OleDbDataAdapter(command)
        Dim MyData As New DataSet
        DataAdapter.Fill(MyData, "Login")

        Me.DataGridView1.DataSource = MyData.Tables("Login")

        TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value.ToString()
        TextBox4.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value.ToString()
    End Sub
esse é o codigo que tenho, e nesta parte:
        TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value.ToString()
        TextBox4.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value.ToString()
as palavras e.rowindex dao erro.

o meu objectivo é quando o utilizador carregar num botão ele fazer uma pesquisa na base de dados pelo username e devolver a password.

Link to comment
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

  • 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.