There is a course called Database lesson set.
My topic: ... Don't talk about it ....
Programming Language: C #
Development environment: Visual Studio Com.
Database: Microsoft SQL Server
First, you have to have a database.
Second, you have to be C #.
The question is how to link the two together.
1. Create a Form project.
2. First create a database with Visual Studio. Concrete Practice here: https://msdn.microsoft.com/zh-cn/library/ms233763.aspx
3. Then add this database to your project's data source: https://msdn.microsoft.com/zh-cn/library/fxk9yw1t.aspx
4. If the name of the database you are building is testdatabase, then look at Solution Explorer and there will be two things: Testdatabase.mdf & testdatabasedataset.xsd.
The first one is the database you set up, the second is the VS for your database ... A thing ... is used to access your database.
There's a name space testdatebasedatasettableadapters, named xxxdatasettableadapters,xxx is your database name.
The usertableadapter in this space is a data type that, after instantiation, has access to the contents of the database.
VS will be very humane to show its members, so do not repeat it.
Here is the code of this test, of course, this is a very lame thing, I also feel very frustrated. But don't worry, I will gradually improve it. Putting the code here is mainly when a simple example is seen.
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten usingSystem.Data.SqlClient; One A - namespacedatabesetest - { the Public Partial classMain:form - { - PublicMain () - { + InitializeComponent (); - } + A Private voidBtnserach_click (Objectsender, EventArgs e) at { - stringUsrid =Txtusrid.text; - txtusrid.clear (); -Testdatebasedatasettableadapters.usertableadapter Testadapter =NewTestdatebasedatasettableadapters.usertableadapter (); -testdatebasedataset.userdatatable table =Testadapter.getdata (); -Txtmain.text ="user Id user Name \ r \ n"; in foreach(DataRow rowinchtable. Rows) - { to if(((string) (row[0])). StartsWith (Usrid)) +Txtmain.text + = row[0] +""+ row[1] +"\ r \ n"; - } theMessageBox.Show ("Flag"); * } $ Panax Notoginseng Private voidBtncreateconnection_click (Objectsender, EventArgs e) - { theMessageBox.Show (" nothing to do"); + } A the Private voidBtninsert_click (Objectsender, EventArgs e) + { - stringUsrid =Txtusrid.text; $ stringUsrname =Txtusrname.text; $ txtusrid.clear (); - txtusrname.clear (); -Testdatebasedatasettableadapters.usertableadapter Testadapter =NewTestdatebasedatasettableadapters.usertableadapter (); the Try - {Testadapter.insert (Usrid, usrname);}Wuyi Catch(Exception Exception) the {MessageBox.Show (Exception). Message); } - } Wu - Private voidBtndelete_click (Objectsender, EventArgs e) About { $MessageBox.Show ("TODO"); - } - - Private voidBtnupdate_click (Objectsender, EventArgs e) A { +MessageBox.Show ("TODO"); the } - $ Private voidBtnrefresh_click (Objectsender, EventArgs e) the { theMessageBox.Show ("TODO"); the } the } -}
Main.cs
The From interface is like this.
Visual Studio from & DataBase (1)