Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6746721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:21:23+00:00 2026-05-26T12:21:23+00:00

im fairly new to databases in vb.net and i have just learned how to

  • 0

im fairly new to databases in vb.net and i have just learned how to use datagridview. im gonna show some of my code for the connection and datagridview display

Public Class Form1


Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String

Dim ds As New DataSet 'holds table data
Dim da As OleDb.OleDbDataAdapter 'connection to database connectionobject
Dim sql As String

Dim inc As Integer
Dim MaxRows As Integer


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

    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    dbSource = "Data Source = C:/AddressBook.mdb"

    con.ConnectionString = dbProvider & dbSource

    'alternative way of connection
    'Dim fldr As String
    'Environment is the user profile
    'fldr = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "/AddressBook.mdb"
    'dbSource = "Data Source = " & fldr

    con.Open()
    MsgBox("Database is now Open")

    sql = "select * from tblContacts"
    da = New OleDb.OleDbDataAdapter(sql, con)
    da.Fill(ds, "Addressbook")


    con.Close()
    MsgBox("Database is now Closed")



    MaxRows = ds.Tables("AddressBook").Rows.Count
    inc = -1
    MsgBox(MaxRows)

    TextBox1.Text = inc

    DataGridView1.DataSource = ds
    DataGridView1.DataMember = "AddressBook"

End Sub     

End Class

the interface

i want to display in a textfield the first name based on where is the pointer is positioned after i clicked Button1, how do i do this? thank you for the replies!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:21:23+00:00Added an answer on May 26, 2026 at 12:21 pm

    You need to get that value from the data grid itself, and then show it on the form. There are other ways, but try this (and add null checks!):

    Dim row as DataRow = CType(DataGridView1.CurrentRow.DataBoundItem, DataRowView).Row
    myTextBox.Text = row["firstName"].ToString();
    

    C#

    var row = ((DataRowView)dataGridView1.CurrentRow.DataBoundItem).Row;
    myTextBox.Text = row["firstName"].ToString();
    

    Alternately:

    If you use a DataSource, and bind the grid to that first, then fill the DataSource with the data, you can use the .Current property to get the selected row.

    Edit:

    Mistake in code. It should be “DataBoundItem”. Not “DataItem”. From memory… Also, you need to cast to string, ctype(...,string) or call .ToString().

    If you bind to a list of objects, then you won’t need to call the .Row, the DataBoundItem will be the actual object type, eg Customer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to working with relational databases, but have read a few books
I'm fairly new to Visual Studio (specifically Visual Basic .NET) but have been programming
I am fairly new to asp.net, and have little experience with iis. I would
I'm fairly new to database programming in WinForms, and have been using BindingSource, DataSet,
Being fairly new to JavaScript, I'm unable to discern when to use each of
I'm fairly new to ASP.NET and trying to learn how things are done. I
I am fairly new to Emacs and I have been trying to figure out
I'm fairly new to database programming in .NET. If I want to call several
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
I'm a fairly experienced developer (.NET, C#, XML, Webservices, HTML, Javascript, various databases etc.)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.