开发者

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

database for c# form

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜