In the past I was able to use SQL select statements on a flat file from VBA from within Excel.
How can I do something similar in C# using VS 2013?
As an overview, I'm creating a desktop app that needs to search a static table of ~100k rows and 6 columns and I'm thinking it doesn't warrant incorporating a real db.
Any pointers or other ideas out there?
Fred
LINQ is made for this. It's a layer between 'something' (text file, database, XML etc.) and the LINQ language. Take a look here.
Linq To Text Files
Microsoft has a great tool for querying different filetypes: It's called log parser .
I personally use it for parsing IIS logs ( *.csv)
Have fun ;-)
Related
I want to develop an app for Windows 7 phone. It will be a GRE vocab app. i dont want to use SQL CE, my app will have 3 tables conceptually. I will be using Linq to SQL to querying data. Now i am confuse how should i store data so it is easy for retrival and update.
XML , CSV , XML or any other format ?
For such a simple database, I'd go with either XML or SQLite. Both are queryable from code.
If you want to update external to the application, i.e. if you don't want to write an interface to update the vocabulary words, but would rather just open a file and update it manually, then XML is the way to go.
SQLite may be faster than querying XML (can't speak to this with certainty, but SQLite uses a binary format, which is generally faster), but you'd need to write all the screens to add words, update definitions, etc.
You could use the Isolated Storage or ready to use implementations.
You can use Perst as a data store. I also know that SQLite also works, but I also hear that it's painfully slow.
I want to parse the SQL code of a file .sql using C#.
I want determinate Syntax Check of a file sql, specifically Insert, Update and Delete statements.
Specifically is there any parser freely available which can parse the SQL code in C# .NET ? better is freeware, source code included, and easy use.
I use Oracle
You can try with ANTLR.
On grammar page you will find several grammars related to Oracle.
Unrelated, is there a way to just "Prepare" statement without execution? That way you could have Oracle check syntax and then catch eventual errors in your code. This will help you skip duplicating functionality already present in Oracle. Not to mention problem of handling changes between different versions of Oracle.
Edit:
Re comment about code examples: I used ANTLR briefly and I had hard time finding code examples on internet. Main source I found was examples from ANTLR download page. Now I see that Terence Parr, author of ANTLR, published new book and that accompanying source code contains more ANTLR examples.
Since you don't have much experience with ANTLR, may I, again, suggest that you try another approach, since this is fairly complex area and needs considerable learning effort to get you started. At least, that was my experience.
General SQL Parser can do offline SQL syntax check without connecting to a database. It's support Oracle, SQL Server, DB2, MySQL, MS-ACCESS, Teradata and PostGreSQL.
But it's a commercial SQL library and not open source.
The miniSqlParser can parse and check SQL statements. This is a assembly of C# and open source. SQL Formatter is a web application of indenting SQLs, that use this assembly. Please try it.
Hey, what's the easiest way to use a file-based database with LINQ in C#? It would be best if I could use it without installing extra components.
EDIT: I want to use it for a file index. Not the whole file system, but the database should be not too slow and not too big.
I'd recommend MS SQL Server Compact Edition. Its embedable, small footprint, good performance and you can use Linq2Sql to query it easily. Also it integrates well with Visual Studio IDE and SQL Management Studio.
Are you opposed to using XML?
That's basically what XML is (or, rather, is a major use of XML), and Linq to XML is very powerful.
The way i've implemented this kind of thing previously is to load a csv file into a C# List structure (couldn't say which is best without information on the data), and use Linq to access data from there.
This may not be the best solution for you, but you have given limited information on what you're looking for.
You will always need to install database drivers to talk to a specific database. The only way to avoid that is to create your own driver to talk to a database, or even create your own database engine.
However, both SQLite and VistaDB have LINQ to SQL now. Other alternatives are to use a text file or XML file for your "database."
I need to import the data form .csv file into the database table (MS SQL Server 2005). SQL BULK INSERT seems like a good option, but the problem is that my DB server is not on the same box as my WEB server. This question describes the same issue, however i don't have any control over my DB server, and can't share any folders on it.
I need a way to import my .csv programatically (C#), any ideas?
EDIT: this is a part of a website, where user can populate the table with .csv contents, and this would happen on a weekly basis, if not more often
You have several options:
SSIS
DTS
custom application
Any of these approaches ought to get the job done. If it is just scratch work it might be best to write a throwaway app in your favorite language just to get the data in. If it needs to be a longer-living solution you may want to look into SSIS or DTS as they are made for this type of situation.
Try Rhino-ETL, its an open source ETL engine written in C# that can even use BOO for simple ETL scripts so you don't need to compile it all the time.
The code can be found here:
https://github.com/hibernating-rhinos/rhino-etl
The guy who wrote it:
http://www.ayende.com/blog
The group lists have some discussions about it, I actually added bulk insert for boo scripts a while ago.
http://groups.google.com/group/rhino-tools-dev
http://groups.google.com/group/rhino-tools-dev/browse_thread/thread/2ecc765c1872df19/d640cd259ed493f1
If you download the code there are several samples, also check the google groups list if you need more help.
i ended up using CSV Reader. I saw a reference to it in one of the #Jon Skeet's answers, can't find it again to put the link to it
How big are your datasets? Unless they are very large you can get away with parameterized insert statements. You may want to load to a staging table first for peace of mind or performance reasons.
I am just beginning to write an application. Part of what it needs to do is to run queries on a database of nutritional information. What I have is the USDA's SR21 Datasets in the form of flat delimited ASCII files.
What I need is advice. I am looking for the best way to import this data into the app and have it easily and quickly queryable at run time. I'll be using it for all the standard things. Populating controls dynamically, Datagrids, calculations, etc. I will also need to do user specific persistent data storage as well. This will not be a commercial app, so hopefully that opens up the possibilities. I am fine with .Net Framework 3.5 so Linq is a possibility when accessing the data (just don't know if it would be the best solution or not). So, what are some suggestions for persistent storage in this scenario? What sort of gotchas should I be watching for? Links to examples are always appreciated of course.
It looks pretty small, so I'd work out an appropriate object model, load the whole lot into memory, and then use LINQ to Objects.
I'm not quite sure what you're asking about in terms of "persistent storage" - aren't you just reading the data? Don't you already have that in the text files? I'm not sure why you'd want to introduce anything else.
I would import the flat files into SQL Server and access via standard ADO.NET functionality. Not only is DB access always better (more robust and powerful) than file I/O as far as data querying and manipulation goes, but you can also take advantage of SQL Server's caching capabilities, especially since this nutritional data won't be changing too often.
If you need to download updated flat files periodically, then look into developing a service that polls for these files and imports into SQL Server automatically.
EDIT: I refer to SQL Server, but feel free to use any DBMS.
My temptation would be to import the data into SQL Server (Express if you aren't looking to deploy the app) as it's a familiar source for me. Alternatively you can probably create an ODBC data source using the text file handler to get you a database-like connection.
I agree that you would benefit from a database, especially for rapid querying, and even more so if you are saving user changes to the data. In order to load the flat file data into a SQL Server (including Express), you can use SSIS.
Use Linq or text data to list method
1.create a list.
2.Read the text file line by line (or all lines).
3.process the line - get required data and attach to the list.
4.process the list for any further use.
the persistence storage will be files and List is volatile.