Quick and dirty reports based on a SQL query - c#

I never thought I'd ever say this but I'd like to have something like the report generator in Microsoft Access. Very simple, just list data from a SQL query.
I don't really care what language is used as long as I can get it done fast.
C#,C++,Python,Javascript...
I want to know the quickest (development sense) way to display data from a database.
edit :
I'm using MySQL with web interface for data input. I would be much better if the user had some kind of GUI.

Depends on the database -- with [sqlite][1], for example, ...:
$ sqlite3 databasefile 'select foo, bar from baz'
is all it takes (see the URL I pointed to for more options you can use, e.g. to change the output format, etc). Mysql has a similar command-line client (see e.g. here), so does PostgreSQL (see here), etc, etc.
So, what specific DB engine are you concerned with? Or, if more than one, which set?

Some suggestions:
1) ASP.NET Gridview
---use the free Visual Studio to create an asp.net page
...can do VB, C#, etc.
---drag/drop a gridview control on your page, then connect it to your data and display fields, all via wizard (you did say quick and dirty, correct?). No coding required if you can live within the wizard's limitations (which aren't too bad actually).
The type of database (mySQL or otherwise) isn't relevant.
Other quick and dirty approach might be Access itself -- it can create 'pages', I think, that are web publishable.
If you want to put a little more work into it, ASP.NET has some other great controls / layout capability (non-wizard derived).
Also, you could look at SSRS if you have access to it. More initial setup work, but has the option to let your users create their own reports in a semi-Access-like fashion. Web accessible.
Good luck.

Related

Correct solution for persistent table/grid in C# that does not require a full database solution?

My WinForms C#/.NET application requires a table/grid control to display records to the end user. The records will be simple, containing only two fields, a string and a date/time field. I need to persist the data and I am wondering what the most efficient control and storage back-end is to use. The data is non-critical (i.e. - not health or financial records, or anything sensitive requiring extensive safety or any encryption).
One solution I have found so far is the DataGrid control in conjunction with SQL Server Compact Edition. I learned about this solution from this tutorial:
http://www.dotnetperls.com/datagridview-tutorial
It seems though that this may be overkill for my application. In addition, I am worried about the complexities of installing SQL Server CE, especially when it comes to admin vs. user account privilege issues during installation:
http://msdn.microsoft.com/en-us/library/aa983326(v=vs.80).aspx
Is there a table or grid control with built-in file load/save capabilities that uses a simple disk file as the storage method, perhaps a comma delimited ASCII file? I'd like something that I can still use SQL (via LINQ) to interface with. also, I am hoping that this can be done transparently. That is, if I want to upgrade to an SQL database engine solution later, the code from my end that interfaces with the data would not change (except perhaps for the database open/create code of course).
Or am I better off simply biting the bullet and going with SQL Server CE or perhaps SQLite:
Good embedded database solution (like SQLite) for .Net
If you have any caveats or anecdotes regarding installation issues and ease of use, they would be appreciated.
In my projects, we use Object datasources. Grid's can be bound to collections of objects just as easily as they can dataTables. You can store/restore the data using a simple serialization engine (XmlSerializer is rather easy to implement). Make a basic object, use List or BindingList as the dataset, and serialize/de-serialize it in the backEnd when you need it.
List and BindingList both support Linq queries.
Adding database save later is as simple as writing the code that saves the object to the database, in place of the serialization code, no change to the front end at all.
As far as a "Correct" solution is concerned...there are so many different ways to do it that it boils down to personal preference, and possibly actual requirements and expected future development. I find it easier to code using objects because the data manipulation is easier, but if you are going for straight record entry, no data manipulation required, going direct to a database is easier. It just depends on the data and what you plan on doing with it.
I strongly recommend you to use an embedded database, because it will be easier to go to a full database in a near future. SQL Server CE is a good option, and if you want to go big you can simply go to a full SQL Server Database with minimal changes in your code, the only downside of SQL Server CE is that you need to install it and it requires the .NET Framework 4, aside from that I don't see a big problem with it.

SQL table / view designer in c#

I am developing an application that requires "some" customization by the enduser afecting the database design (beyond the parametrization).
Now a days this application supports to work with new columns for the existing tables or even new tables in runtime. But the enduser is not capable to alter the tables, and all the design work must be done using Microsoft SQL Server Magament Studio.
My question is: there is any kind of control (or tool) which implements this functionality? I would like to have it embeded in my application, but if it is a external tool wouldn't be so bad.
What I want to have is some tool that let the user define a repository of columns (name, type, size) for example:
CustomerCode, BIGINT, n/a
CustomerName, Varchar, 50
And then create or alter a table or view by adding these predefined columns. And underneath should execute the needed SQL script or maybe using SMO (SQL Management Objects).
Updated
Currently it's the application works with WinForms, but any WPF / ASP solution would be appreciated.
And referring to and enduser I mean a app administrator but not with programing skills.
Purpouse
The purpose is to be able to extend and customize the functionality from the own apllication without having to use SQL Server Managment Studio.
Imagine that you have an ERP, as a user you want to inform in your customers table something that the application was not orginally intended and even has no free fields for it, for example: GPS location, logo, CEO's photo...
Of course I can suggest to some advanced users to install SSMS Express, but that will give them too much freedom. I also think it is a IT tool. What I wanted is to develop the capability to modify the application from the own framework of the application.
If it can be done from the own application, some controls can be performed:
Check that a table field called X will be always defined with the same type,
Disable the capability to modify the non-customizable fields (application fields),
...
Alex, I think you should try to give the user the flexibility to add new information to the database without really change the design of the database.
You can take a look at EAV Model (entity-attribute-value). This give you the flexibilty to add any new attribute to customer without change the design of customer table (e.g.).
One good example is Magento, they did a great job with EAV (entity-attribute-value) but you must know that this design model will hit your performance a little (or a lot depends how you implement it).
It seems that this kind of control does not exists, so I will scratch it from 0.
#BrunoCosta's idea of using an EAV model to extend the standard application is a good practice. But I pretend to have a tool to modify the standard, and have a tool used for the final user and also for the developer. A pseudo SQL Server Studio + Visual Studio embedded in the a application.
Once I develop it, I will to post it in CodeProject.
I think that the control you are looking for may be a little too unique. However, I don't think it would be too difficult create this yourself using other controls/libraries.
I am just finishing up a similar WPF project.
I found that the DataGrid class worked well for representing a table. You can add/remove columns programmatically. Although you would be generating the SQL script yourself.

Which Data Source

I have an xl spreadsheet that I'd like to scrap. I'll replace it with a simple windows form application built with c#.
The spreadsheet has a table with just two columns:
Date
Staff Member
So a sample of the table might look like:
01-Jan Jason
02-Jan
03-Jan Mike
As you can see it's very simple. I use Sqlserver everyday but it would seem like overkill to put this table into a db on Sqlserver. What datasouce should I use for the windows form - a text file?
note: not sure if it influences my choice of datasouce but I'm thinking of using a calender tool and maybe a datagridview in the form.
Seems so simple that you can use a simple text file(key-value), but if you want to expand the capability of the program in the future maybe it is better to put the table in a SQLite database, that is a lightweight embedded database and should fit well with your requirements.
Its not overhead to use sql server at all, if you wish to ditch the file/spreadsheet.
Also using sql-server will be a consistent method of data storage if that is what you currently use for other apps.
It really should take very little time to do.
Also assuming your sql setup does automatic backups etc, then it will ensure you don't lose the information. Hands down make use of sql server if you have access to it.
If you are used to using SQL Server everyday, the closest thing to that is SQL Server Compact, as it is very similar to SQL Server but designed instead to be used as a lightweight, standalone option. It interfaces with Visual Studio and you should feel right at home with it.

How do I assign a sql record value to string in asp.net

I'm new to asp, so be patient :p
I have an sql database, with a users table that has username and a colour.
My asp master page is reading the current users username and passing it to the content fine.
What I am trying to now do is in the content page grab the colour from the sql table where the username is the current username, and assign it to a string inside the default.aspx.cs file.
How do I do this?
Cheers
Honestly, and don't take this offensively, but perhaps diving straight into writing a database-driven ASP.NET application isn't where you should be starting out.
I would attempt to learn more about the ASP.NET architecture first, learn the language well (VB.NET or C#), and start with something simpler.
With that said, and assuming you're going to attempt this anyway, what you are probably going to want to start out with is ADO.NET. Microsoft, through MSDN, provides a good page full of ADO.NET Code Examples.
You'll have to define a connection string to your database, which may include specifying a third-party driver if you're using a database such as Sybase or MySql, or using an entirely different set of provider classes such as what you'd need for Oracle. Next you'll create a command containing your SQL query and execute the command. You need to consume the results and pull your value out of a result set, and then clean up the close the connection.
Check out the link; hopefully it will get you started. There are a ton of examples of ADO.NET sprinkled across the Interwebs, I'm sure you can find a working example.
If you want to skip ADO.NET and try something a bit more O/R mappery (and are using Microsoft SQL Server), you might be interested in checking out LINQ to SQL.
EDIT
From your comments, your question is about how to read a value from SQL Server. The most basic way is by just opening a SqlConnection, create a SqlCommand, setting the command text, etc etc. There are many tutorials online. Unfortunately you run the risk of Sql Injection attacks that way.
The best way is to set up an OR Mapper, which creates objects for you, that map directly to your database. The best option there would probably be Entity Framework 4. There are plenty of tutorials online.
END EDIT
Probably the best thing to do would be to set a property in your master page, and then have your default.aspx page read the value from the master page, and do whatever it wants with it.
Having said that, it's usually a bad idea to be doing database reads from your UI. Usually you'll want to push that stuff off to another tier, and have your UI focus on just doing UI things.
But, assuming this is just a simple project, then something like the following line should get you where you need to go:
From default.aspx:
string value = (this.Master as YourMasterPageClass).YourProperty;

Save Sharepoint Data outside of Lists

What is the best way to store your Data outside of SharePoint. I want to use the default Edit/View options in SharePoint (though I do plan on extending their functionality). I need to store the data outside of the SharePoint Lists as I am expecting a large record set(150,000 to start with).
I totally agree with GalacticJello, storing data outside of the regular sharepoint content database is at the moment (MOSS 2007) a complete and utter nightmare. MS provided a ExternalStorage provider baseclas for us to override, but there are major cons against using this:
writing and using your own custom ExternalStorage provider implementation is doable, but very difficult
ExternalStorage provider implementations only do just that, making sharepoint store stuff in a different location than the regular content db.
This means that you would need to write your own code to keep the external storage and the list items in sync, and i'm not even mentioning workflows and versioning.
last but not least (and IMHO the worst), creating and using a custom ExternalStorage provider is not web app or site collection targetable, it's usage is farm wide (and there are NO workarounds). So any site collection you create in that farm will have it's doc libs use the external storage provider.
You can store the items in the list, the trick is to create efficient views that return paged data quickly back to the user.
Another option is to use folders to split up the data.
If you really need to store it outside of SharePoint, I would consider waiting for SharePoint 2010 and thier "External Lists" features, as there are a ton of pitfalls and things to consider if you want to mimic that functionality in SharePoint 2007 (been there, done that).
You could create a SQL Data source and use the Data Form Web part to connect it to an edit form etc.:
Data Forms and SQL Server, Part 1
Data Forms and SQL Server, Part 2
Personally I prefer to have the level of control of a totally custom web part.. with this you will not run into limitations eventually.
In this case it sounds like all the elements will be in the same list, otherwise SLAM (free tool on CodePlex) is a very neat data replication tool for related lists.
Based on the comments above it sure looks like a plain ol' ASP.NET page might be the best option, unless there is some good reason why SharePoint must be used.

Categories

Resources