Home > Back-end >  Use the information in the text file program reads in access databases
Use the information in the text file program reads in access databases

Time:09-30

With software is vs2010, want to in the single document file that has no database support text document read access database, whether need to put the. TXT file with code into the first MDB file?
After be used in the dialog box, and realize the query function,

CodePudding user response:

TXT is TXT, the MDB is the MDB, two steps, first to read text files to your memory (a little) can, of course, reading, according to the rules of your each record, and then inserted into the database

CodePudding user response:

Don't need to read by flow straight binary field

CodePudding user response:

Robots.txt file. It is difficult to convert the MDB file, unless the above procedures according to the records, field one by one, insert
.txt easy to CSV

CodePudding user response:

Now, will create the MDB database file, and insert a set of data, but the content of the reading from the text document is on cstrings type variable, the with db. I temporarily haven't found the Execute (_T (" insert into the Login Account, Password) values (' fuyanzhi ', 'yulin) ")); Similar methods insert cstrings type string,

The code is as follows:
CDaoDatabase db.
CDaoRecordset RecSet (& amp; Db);

Cstrings sPath;
GetModuleFileName (NULL, sPath GetBufferSetLength (MAX_PATH + 1), MAX_PATH);

SPath. ReleaseBuffer ();

Int nPos.

NPos=sPath. ReverseFind (' \ \ ');//return the cstrings object and requirements of character matches the last character of the index

SPath=sPath. Left (nPos);

Cstrings lpszFile=sPath + "\ \ TestDb MDB".
The db. The Create (lpszFile);

Cstrings SqlCmd=_T (" CREATE TABLE Login (Account VARCHAR (10), Password VARCHAR (10));" );

The db. The Execute (SqlCmd);//create the first table createfield createindex

Cstrings a, b;
A.F ormat (_T (" asdfs "));
B. ormat (_T (" Lin "));
The db. The Execute (_T (" insert into the Login (Account, Password) values (' fuyanzhi ', 'yulin) "));//insert normal
Db. The Execute (_T (" insert into the Login (Account, Password) values (' % s', '% s'). A, b "));//execution times and cannot be inserted into the wrong

CodePudding user response:

Convert a text file to a CSV file or separated with a special symbol and then line inserted into the MDB file

CodePudding user response:

If the text file is a typical CSV format, then open Acces application database and execute the following SQL:
 SELECT * INTO [Table1] FROM [TEXT; FMT=CSV, DELIMITED; HDR=YES; DATABASE=E: \ Temp \]. [test. CSV]; 

CodePudding user response:

Problem has been solved, thank you,
  • Related