Combobox, datasource and text file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Does anyone know how to bind text file to a datasource (of a combobox in my
case)?

I went through the properties, but it seems like the only "boundable"
sources are databases such as Acess, SQL server or Oracle?

Any help is greatly appreciated.
 
How about this:
Read your text file, split it into an array of rows based on the line feed
at the end of each line, then split each row into an array based on whatever
delimiter is present (comma, semicolon, etc. if any).
Then create a Datatable, create a column for each column in the text file,
and iterate over each row array.
Use
DataRow row = myTable.NewRow()

to create a new dataRow, assign your array of items to the rows ItemArray
property, and add the new row to your datatable with
myTable.Rows.Add(row)
When you are done with your loop, you can bind the datatable to the control.
Peter
 
Thanks Peter.

Unfortunately, this is exactly what I have implemented. What I was looking
for was whether there is a direct binding capability. It maybe difficult to
do, as I can imagine it's hard to standardize "text file database".
 
What is the format of your Text File? MS Jet Engine can read a Formated
Text File directly, and you can use it in .NET application with OLEDB
Connection. For example, follow Text can be read by Jet:

1, Tom, 24
2, Jack, 32
3, Luke, 55

Regards,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Great!

My text file is in a simliar format. 2 fields delimited by , or ;.

My exposure to Jet Engine is limited. Do I create a "Jet Engine" object,
mapped to datafile? Do I then assign this object to the Combobox.datasource?

Thanks,
 
Here is a sample:

MyConnection = New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\""")

MyCommand = New System.Data.OleDb.OleDbDataAdapter( select * from
test.txt", MyConnection)

DS = New System.Data.DataSet()

MyCommand.Fill(DS)

Also, you can connect to the TEXT file with ODBC: Create a ODBC DSN in ODBC
data source administrator with "Microsoft Text driver". In VS.NET 2005,
open server explorer, add a database connection, choose "Microsoft ODBC
Data Source and select the ODBC DSN you created.

Regards,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi,

I have followed the example and was able to get it to work. Thanks.

I have encountered additional issues after making some progress. I also
have some general quesitons as well.

Q1. Can you point me to a specification for how to build a connection
string, e.g.
"Provider=Microsoft.Jet.OLEDB.4.0;Data ...."

Q2. Is there a specification of how to construct a comma demilited text
database file?

Q3. I am struggling with updating the text file database once the user has
made change to the DataTable through my DataGridView (as databound source).
I have tried to use OleDbCommandBuilder. However, I kept getting an
exception stating
"SelectCommand that does not return any key column information" when
OleDbCommandBuilder.GetDeleteCommand() is executed. I suspect that I need to
specify the primary key here. However, the only method I know is to specify
Primary key in my DataTable. This does not work either. Any thoughts?

Q4. (re Q2 and Q3), Can I specify primary key information in the comma
delimited text file?

Thanks,
 
Hello,

For delimited text file, we cannot set primary key.Therefore, we cannot
update it also. Regarding connection string of JET, you may refer to:

http://support.microsoft.com/default.aspx?scid=kb;en-us;326548

Regards,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Back
Top