How put a Dataset in a Datagridview

F

Freddy Coal

Hi, I'm newbye in that theme. I would like put the data of a dBase in a
DataGridView, why make that?.

I'm open my database with this instructions:
'----------------
Dim Tabla As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" _
& Folder & ";Extended Properties=dBASE IV")
Tabla.Open()
Folder = Path.GetFileNameWithoutExtension(ruta) 'Name of the file

Dim Comando As New OleDbCommand("Select * From " & Folder, Tabla) 'Select
all values in the dBase
Dim da1 As New OleDbDataAdapter(Comando)
Dim DataSet As New Data.DataSet

da1.Fill(DataSet) 'I put all the info in the dataset.

Tabla.Close()
'----------------

Now I need put all that data in a Datagridview, and I don´t find an example
about how make that; My datagridview is clear, don't have any columns, I
would like add diferent dBase and make columns and rows for each database.

Thanks in advance for any help.

Freddy Coal
 
T

Tom Shelton

Hi, I'm newbye in that theme. I would like put the data of a dBase in a
DataGridView, why make that?.

I'm open my database with this instructions:
'----------------
Dim Tabla As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" _
& Folder & ";Extended Properties=dBASE IV")
Tabla.Open()
Folder = Path.GetFileNameWithoutExtension(ruta) 'Name of the file

Dim Comando As New OleDbCommand("Select * From " & Folder, Tabla) 'Select
all values in the dBase
Dim da1 As New OleDbDataAdapter(Comando)
Dim DataSet As New Data.DataSet

da1.Fill(DataSet) 'I put all the info in the dataset.

Tabla.Close()
'----------------

Now I need put all that data in a Datagridview, and I don´t find an example
about how make that; My datagridview is clear, don't have any columns, I
would like add diferent dBase and make columns and rows for each database.

Thanks in advance for any help.

Freddy Coal

MyDataGridView.DataSource = DataSet.Tables("TheTableToDisplay")
 
F

Freddy Coal

Thanks Tom, that is the instruction, now I have another problem, how I can
open files with others characters like ñíó, space...etc?

I try to open a database in the next path:

C:\Documents and Settings\fcorredor.Company\My Documents\Visual Studio
2005\@Reservorio\Carto\Estaciones_font_point.dbf

And in the line: da1.Fill(Dataset)

I get the next error:

'-------
System.Data.OleDb.OleDbException: '' is not a valid name. Make sure that it
does not include invalid characters or punctuation and that it is not too
long.
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at
System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
'-------

Or when I try open dBase with special characters I get:

'-------
"System.Data.OleDb.OleDbException: Syntax error in FROM clause.
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,
Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at
System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
'-------

I'm using this command for open the dBase file:

Dim Tabla As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" _
& Folder & ";Extended Properties=dBASE IV")

Thanks in advance for your help.

Freddy Coal


Hi, I'm newbye in that theme. I would like put the data of a dBase in a
DataGridView, why make that?.

I'm open my database with this instructions:
'----------------
Dim Tabla As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" _
& Folder & ";Extended Properties=dBASE IV")
Tabla.Open()
Folder = Path.GetFileNameWithoutExtension(ruta) 'Name of the file

Dim Comando As New OleDbCommand("Select * From " & Folder, Tabla) 'Select
all values in the dBase
Dim da1 As New OleDbDataAdapter(Comando)
Dim DataSet As New Data.DataSet

da1.Fill(DataSet) 'I put all the info in the dataset.

Tabla.Close()
'----------------

Now I need put all that data in a Datagridview, and I don´t find an
example
about how make that; My datagridview is clear, don't have any columns, I
would like add diferent dBase and make columns and rows for each database.

Thanks in advance for any help.

Freddy Coal

MyDataGridView.DataSource = DataSet.Tables("TheTableToDisplay")
 
M

Mr. Arnold

Freddy Coal said:
Thanks Tom, that is the instruction, now I have another problem, how I can
open files with others characters like ñíó, space...etc?

I try to open a database in the next path:

C:\Documents and Settings\fcorredor.Company\My Documents\Visual Studio
2005\@Reservorio\Carto\Estaciones_font_point.dbf

And in the line: da1.Fill(Dataset)

I get the next error:

'-------
System.Data.OleDb.OleDbException: '' is not a valid name. Make sure that
it does not include invalid characters or punctuation and that it is not
too long.

"." is a punctuation character.

"@" is a special character and may be invalid.

Move the file to a folder with a name that is less complicated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top