SQL table / view designer in c# - 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.

Related

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 to use a local database in c#?

I've made a local database for a C# project:
I know basic SQL commands, but haven't worked with databases in C#.
What I'd like to know specifically is:
How to read from the database (query)
How to add and update rows
The database only consists of 3 tables, so I don't think anything fancy is needed.
First, you should learn a bit about various technologies and APIs for connecting with a database.
The more traditional method is ADO.NET, which allows you to define connections and execute SQL queries or stored procedures very easily. I recommend digging up a basic tutorial on ADO.NET using Google, which may differ depending on what type of project you're creating (web app, console, WinForms, etc).
Now days, ORMs are becoming increasingly popular. They allow you to define your object model in code (such as every database table would be a class, and columns would be properties on that class) and bind to an existing database. To add a new row to a table, you'd just create an instance of a class and call a "Save" method when you're done.
The .NET framework has LINQ to SQL and the Entity Framework for this sort of pattern, both of which have plenty of tutorials online. An open source project I really like is Castle Active Record, which is built on top of NHibernate. It makes defining ORMs quite easy.
If you have specific questions about any of the above, don't hesitate to post a new question with more specific inquiries. Good luck!
Update:
I thought I'd also put in one last reference as it seems you might be interested in working with local database stores rather than building a client/server app. SQLite allows you to interact with local stores on the file system through SQL code. There's also a .NET binding maintained by the SQLite guys (which would in theory allow you to work with the other platforms I mentioned): http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
You can use SQLCE.
This blog will give you a good start.
http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
Here is a small tutorial that should be helpful to you.
You can make use of the SqlDataReader to read data
and the SqlCommand to Insert Update Delete rows from your tables.
http://www.dotnetperls.com/sqlclient
You could use it by adding following to your Startup.cs
services.AddDbContext<DemoDbContext>(options => options.UseSqlite("Filename=data.db"));

database for c# form

I am doing a school project in C# apps and I decided to create a ticketing system.
I want to impress my teacher (^^) so I decided to add a database for my app.
I have a month to do this so i think I can learn it since I don't have any prior experience with databases.
Could you tell me how to do it? Below is my app, I want to send the info in the TextBox to a database
I already followed the instructions in MSDN which basically tells you how to add a data source in your app. I added northwind dataset to my app, but I don't know what to do with it and how will it be useful with my app...
For a SQL backend, you can use SQLite quite easily. SQLite is simply a file that resides on the local system, so it is totally portable/deployable with your application. It comes with the caveat that the database is not shared between users. It is a single user database. Two people running an application based on SQLite will not share data. For a uni assignment, this is probably not going to be a big deal.
You could also use SQL Server CE (compact edition), which is a stripped down SQL Server implementation which is similar to SQLite (local, embedded, single user). This will allow you to use Visual Studio database tools to design your database.
Once you have a database embedded within your application, you need to design a schema to hold on to this information. If your screenshot is the only data you need to save, a table like the following should do the trick:
TABLE PERSON
COLUMN name varchar(100)
COLUMN address varchar(200)
COLUMN email varchar(100)
COLUMN mobile varchar(15)
You will need to investigate how to create tables in SQL. That should guide you in what you need though. Visual Studio (some versions), also have a database browser/designer.
Then you need to decide how you want to communicate with the database. You have several options.
Linq 2 SQL
Entity
DataTables
Scott Gu has an excellent series on how to use Linq 2 SQL which I would highly recommend reading. It will go the majority of the way to helping you get to where you need.
So now that you have a SQL database and a provider, you can start trying to wire up the database to the form. This is where databinding comes in. You can drag a Data Source onto a form (which is your Person table), and wire up the table to your text fields. There are many examples on the net how to do this.
If you want to take it a step further, look into the ErrorProvider control. It will allow you to bind validation to your data source and text fields. Once again, a few google searches should point you in the right direction.
I haven't provided code samples because this is homework. If you want to impress your teacher, you will do so by truly understanding the technology you're trying to use. These are just pointers in the right direction so you know what it is you can investigate. Best of luck.
That is a pretty broad question, is there something specifically that you need help with? Like connect to the database, use a datareader, etc...?
If you want to impress your teacher, don't refer to MSDN. Use something like couchdb. Don't get caught up in the "prescribed " .net ecosystem.

How to generate basic form to edit database entry quickly?

Is there a way I can generate form in WinForms or window in WPF that can insert/edit entry in database table?
If shortcut doesn't exist can you share your experience how can I do it quickly with least effort.
I have a large project in which I have to spend lots of time modeling database and I wish to skip the visual design part and complete the application as soon as possible and then when I have time do the design right.
There are a number of tools out there that can generate such a form for you imho the best is "Codesmith".
There is a pattern/code generation system baked into Visual Studio called "T4"
(http://msdn.microsoft.com/en-us/library/bb126445.aspx) that is not terribly well documented but effective once you work your way through it.
If you want more control over the system, you can use various sql functions to list the tables in a db, the fields in a table (and the datatype for each field...) etc. etc. and roll your own, it really isn't that hard.
Cheers,
CEC

Quick and dirty reports based on a SQL query

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.

Categories

Resources