textbox path to be populated in datagrid

david_reinjal

Member
Joined
Jun 24, 2006
Messages
8
Programming Experience
Beginner
hi guys,
i have the following code,
VB.NET:
[SIZE=2][COLOR=#0000ff]
Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnopendb_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnopendb.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] OpenFileDialog1
[/SIZE][SIZE=2][COLOR=#008000]' Check to ensure that the selected file exists. Dialog box displays a warning otherwise.
[/COLOR][/SIZE][SIZE=2].CheckFileExists = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' Check to ensure that the selected path exists. Dialog box displays a warning otherwise.
[/COLOR][/SIZE][SIZE=2].CheckPathExists = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' Get or set default extension. Doesn't include the leading ".".
[/COLOR][/SIZE][SIZE=2].DefaultExt = [/SIZE][SIZE=2][COLOR=#800000]"MDB"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' Return the file referenced by a link? If False, simply returns the selected link file.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' If True, returns the file linked to the LNK file.
[/COLOR][/SIZE][SIZE=2].DereferenceLinks = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2].InitialDirectory = [/SIZE][SIZE=2][COLOR=#800000]"C:\"
[/COLOR][/SIZE][SIZE=2].Filter = [/SIZE][SIZE=2][COLOR=#800000]"mdb|*.mdb"
[/COLOR][/SIZE][SIZE=2].Multiselect = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2].RestoreDirectory = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'.FilterIndex = 1
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]txtopendb.Text = OpenFileDialog1.FileName
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] exp [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
MessageBox.Show(exp.Message, [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Text)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

when i give the path in textbox then i have to open the database in datagrid. how do i do that?
Thanks
 
im a little rusty with datagrids, if anyone thinks (knows haha) that im wrong just correct me.

you need to create a new oledbconnection using the path from the dialog box. something like this...

dim cnn as new oledbconnection
cnn.connectionstring = TheDialogBox.FileName

dim ds as dataset
dim da as dataadapter

dim scmd as sqlcommand = new slqcommand("SELECT * FROM tbl")
da.selectcommand = scmd
da.fill(ds)

datagrid.datasource = ds 'with this part it might be instead ds.tables(0)

im a little hazy on that part, anyone can add any more would be great
hope that helps a little
cheers
adam
 
Back
Top