Visual Studio 2013 - How can I determine what database is being used by a Data Grid View (dgv) control in run time?

Hi Experts,

I am trying to debug my vb.net program.

How can I determine what database is being used by a Data Grid View (dgv) control in run time?

My Data Grid View (dgv) control is dgvMaterials.

When my form is loaded and I check the values of dgvMaterials in the Immediate window using ?dgvMaterials, I get this output:

?dgvMaterials
{System.Windows.Forms.DataGridView}
    AccessibilityObject: {ControlAccessibleObject: Owner = System.Windows.Forms.DataGridView}
    AccessibleDefaultActionDescription: Nothing
    AccessibleDescription: Nothing
    AccessibleName: Nothing
    AccessibleRole: Default {-1}
    AdjustedTopLeftHeaderBorderStyle: {DataGridViewAdvancedBorderStyle { All=NotSet, Left=OutsetDouble, Right=Outset, Top=OutsetDouble, Bottom=Outset }}
    AdvancedCellBorderStyle: {DataGridViewAdvancedBorderStyle { All=Single, Left=Single, Right=Single, Top=Single, Bottom=Single }}
    AdvancedColumnHeadersBorderStyle: {DataGridViewAdvancedBorderStyle { All=OutsetPartial, Left=OutsetPartial, Right=OutsetPartial, Top=OutsetPartial, Bottom=OutsetPartial }}
    AdvancedRowHeadersBorderStyle: {DataGridViewAdvancedBorderStyle { All=OutsetPartial, Left=OutsetPartial, Right=OutsetPartial, Top=OutsetPartial, Bottom=OutsetPartial }}
    AllowDrop: False
    AllowUserToAddRows: False
    AllowUserToAddRowsInternal: False
    AllowUserToDeleteRows: False
    AllowUserToDeleteRowsInternal: False
    AllowUserToOrderColumns: False
    AllowUserToResizeColumns: True
    AllowUserToResizeRows: True
    AlternatingRowsDefaultCellStyle: {DataGridViewCellStyle { }}
    Anchor: Top Or Left {5}
    ApplyVisualStylesToHeaderCells: False
    ApplyVisualStylesToInnerCells: False
    AutoGenerateColumns: False
    AutoScrollOffset: {X = 0 Y = 0}
    AutoSize: False
    AutoSizeColumnsMode: None {1}
    AutoSizeRowsMode: AllCells {7}
    BackColor: "{Name=Control, ARGB=(255, 240, 240, 240)}"
    BackColorBrush: 1048738
    BackgroundBrush: {Color = {Color [AppWorkspace]}}
    BackgroundColor: "{Name=AppWorkspace, ARGB=(255, 171, 171, 171)}"
    BackgroundImage: Nothing
    BackgroundImageLayout: Tile {1}
    BecomingActiveControl: False
    BindingContext: {System.Windows.Forms.BindingContext}
    BindingContextInternal: {System.Windows.Forms.BindingContext}
    BorderStyle: FixedSingle {1}
    Bottom: 322
    Bounds: {X = 0 Y = 0 Width = 664 Height = 322}
    BufferPinkRect: Nothing
    CachedImeMode: NoControl {0}
    CacheTextInternal: False
    CanAccessProperties: True
    CanEnableIme: False
    CanFocus: True
    CanRaiseEvents: True
    CanRaiseEventsInternal: True
    CanSelect: True
    Capture: False
    CaptureInternal: False
    CausesValidation: True
    CellBorderStyle: Single {1}
    CellMouseDownInContentBounds: False
    CellPaintingEventArgs: {System.Windows.Forms.DataGridViewCellPaintingEventArgs}
    CellValueEventArgs: {System.Windows.Forms.DataGridViewCellValueEventArgs}
    CheckForIllegalCrossThreadCalls: False
    ClientRectangle: {X = 0 Y = 0 Width = 664 Height = 322}
    ClientSize: {Width = 664 Height = 322}
    ClipboardCopyMode: EnableWithAutoHeaderText {1}
    ColumnCount: 17
    ColumnHeadersBorderStyle: Raised {2}
    ColumnHeadersDefaultCellStyle: {DataGridViewCellStyle { BackColor=Color [Control], ForeColor=Color [WindowText], SelectionBackColor=Color [Highlight], SelectionForeColor=Color [HighlightText], Font=[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3, GdiCharSet=0, GdiVerticalFont=False], WrapMode=True, Alignment=MiddleLeft }}
    ColumnHeadersHeight: 47
    ColumnHeadersHeightSizeMode: DisableResizing {1}
    ColumnHeadersVisible: True
    Columns: {System.Windows.Forms.DataGridViewColumnCollection}
    CompanyName: "Microsoft Corporation"
    Container: Nothing
    ContainsFocus: False
    ContextMenu: Nothing
    ContextMenuStrip: Nothing
    ControlKeyboardRouting: Nothing
    Controls: {System.Windows.Forms.DataGridView.DataGridViewControlCollection}
    Created: True
    CreateParams: {CreateParams {'', '', 0x56010000, 0x0, {0, 0, 664, 322}}}
    CreateThreadId: 3024
    CurrentCell: {DataGridViewTextBoxCell { ColumnIndex=0, RowIndex=0 }}
    CurrentCellAddress: {X = 0 Y = 0}
    currentHelpInfo: Nothing
    CurrentImeContextMode: Inherit {-1}
    CurrentRow: {DataGridViewRow { Index=0 }}
    Cursor: {[Cursor: Default]}
    CursorInternal: Write Only Properties are not supported
    DataBindings: {System.Windows.Forms.ControlBindingsCollection}
    DataConnection: {System.Windows.Forms.DataGridView.DataGridViewDataConnection}
    DataMember: ""
    DataSource: { [System.Windows.Forms.BindingSource]}
    DefaultBackColor: "{Name=Control, ARGB=(255, 240, 240, 240)}"
    DefaultCellStyle: {DataGridViewCellStyle { BackColor=Color [Window], ForeColor=Color [ControlText], SelectionBackColor=Color [Highlight], SelectionForeColor=Color [HighlightText], Font=[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3, GdiCharSet=0, GdiVerticalFont=False], WrapMode=True, Alignment=MiddleLeft }}
    DefaultCursor: {[Cursor: Default]}
    DefaultFont: {Name = Reference to a non-shared member requires an object reference. Size=8.25}
    DefaultForeColor: "{Name=ControlText, ARGB=(255, 0, 0, 0)}"
    DefaultImeMode: Inherit {-1}
    DefaultMargin: {Left=3,Top=3,Right=3,Bottom=3}
    DefaultMaximumSize: {Width = 0 Height = 0}
    DefaultMinimumSize: {Width = 0 Height = 0}
    DefaultPadding: {Left=0,Top=0,Right=0,Bottom=0}
    DefaultSize: {Width = 240 Height = 150}
    DesignMode: False
    DeviceDpi: 96
    deviceDpi: 96
    < More... (The first 100 of 303 items were displayed.) >

Open in new window


I think what I am looking for is:  DataSource

But all I get is:

    DataSource: { [System.Windows.Forms.BindingSource]}

How can I determine the full path of the DataSource?

Regards,
Leigh
LVL 1
LeighWardleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LeighWardleAuthor Commented:
I think DataSource is:

CIRCLY7.LAYERSDataSet

CIRCLY7 is the name of my .exe file.

LAYERSDataSet is a DataSet.

I've looked at all the properties of LAYERSDataSet, but none show the path to the database.
AndyAinscowFreelance programmer / ConsultantCommented:
Somewhere you will fill the DataSet with data.  For a database then you will have to create and use a connection.
I would perform a search (CTRL+f) in your project for LAYERSDataSet and see if you can find where it is being filled.  Then check the connection.

ps.  For some databases (eg. SQL Server) you will not a path to the source, all you will see is an instance name.
louisfrCommented:
How do you fill the dataset?
ElrondCTCommented:
Once the dataset is filled, it is no longer connected to the database, so the dataset does not contain any information about where the data came from (different parts of the data could come from different sources: multiple databases, imports from other datasets, or adding new rows under program control). So the only way to find out is, as others have indicated, to check your code for a .Fill of the dataset. If you need to know the database used at a later point in the application run, because there could be multiple databases that you're getting the information from, you'll have to set up a separate variable to store the name of the source database, and update it any time you do a .Fill.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Thanks, Elron and Andy, for clear explanations.

Regards,
Leigh
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.