: Web-, 䳺 Microsoft Visual Studio.NET 2012.
: Microsoft Visual Studio 2012 1, 2, , . , .
:
ij Web- , . ֳ , . 볺 , . 㳿 . 95% . 䳿 .
, .NET , ' . Web- :
', .
, , .
. ' , , ,
' , , , , 䳿, .
1
Microsoft Visual Studio 2012, , .
1:
// -.(File/New Web Site). , , : - ASP.NET, Language: Visual C# , .
. 3.1 Web-
2:
-/ (Website/Add New Item) , , SQL Server ' , Test.mdf. ' Server Explorer.
. 3.2
3:
(Server Explorer) Test.mdf (Tables), , ', (Add New Table). ' , , .
, (. 4.3):
|
|
.4.3 ,
groups (Column Name), (Data Type) (Allow Nulls) , . , id, Set Primary .
.3.4 groups ,
, 1, , , id, (Column Properties) (Identity specification) (Is Identity), (Identity Increment) (Identity Seed) Yes, 1, 1 .
.3.5 groups ,
ϳ groups, "groups" , :
CREATE TABLE [dbo].[groups]
(Update), .
. 3.6 groups
.
Test.mdf.
students.(.4.7)
. 3.7 students
4:
' . :
- students , .
. 3.8 students
- , ', ToTable groups.
. 3.9 students
- :
CONSTRAINT [FK_students_groups] FOREIGN KEY ([id_group]) REFERENCES [dbo].[groups] ([Id])
- .
- .
.
5:
Server Explorer , ', (Show Table Data). , , .
2
Visual Studio 2012, , .
1:
, . Server Explorer Data Connections ( ), Add Connection. , ', Browse, .
|
|
2:
groups. Default.aspx . Server Explorer groups . 2 : GridView SqlDataSource. GridView. , GridView . , Enable Editing Enable Deleting.
3:
. .
4:
, groups.
Label Text New group name. Label1.
TextBox TextBox1.
Button Text Insert. Button1.
5:
, ', :
) MS SQL Server System.Data.SqlClient:
using System.Data.SqlClient;
) :
protected void Button1_Click(object sender, EventArgs e)
{
{
// name
String name = TextBox1.Text;
//
if (name == "") return;
//
String query = "INSERT INTO groups (name) VALUES ('" + name + "')";
//
SqlDataSource1.InsertCommand = query;
SqlDataSource1.Insert();
//
TextBox1.Text = "";
}
}
6:
. , .
7:
students .
³ Default.aspx ( Web-: File/New File, , ', Web Form '). Server Explorer students . GridView SqlDataSource. , Enable Editing Enable Deleting.
8:
, students.
7 Label, students, zachetka, surname, name, patronymic, birthdate, tel id_group, Text (, New group New telephone number). Label1.Label7.
6 TextBox, students, zachetka, surname, name, patronymic, birthdate tel. TextBox1.TextBox6.
9:
id_group DropDownList , , , groups. Server Explorer groups Visible GridView False. SqlDataSource SqlDataSource2 SqlGroups, GridView DataSourceID ̳ SqlDataSource2 SqlGroups.
|
|
DropDownList ' , . Choose Data Source. , , groups, , ', Select data source SqlGroups, Select data field to display in the DropDownList name ( groups ), Select data field for the value of DropDownList id ( groups id_group students).
10:
Button Text Insert. Button1.
11:
, ', :
) MS SQL Server System.Data.SqlClient:
using System.Data.SqlClient;
) :
protected void Button1_Click(object sender, EventArgs e)
{
// , , , ,
// ,
// z, s, n, p, b1, a, t
String z = TextBox1.Text;
String s = TextBox2.Text;
String n = TextBox3.Text;
String p = TextBox4.Text;
String b1 = TextBox5.Text;
String t = TextBox6.Text;
//
// g
int g = Convert.ToInt16(DropDownList1.SelectedValue);
// ,
if (z == "" || s == "" || n == "" || b1 == "") return;
// DateTime
DateTime b = Convert.ToDateTime(b1);
//
String query = "INSERT INTO students (zachetka,surname,name,patronymic,birthdate,tel,id_group) VALUES ('" + z + "','" + s + "','" + n + "','" + p + "','" + b + "','" + t + "'," + g + ")";
//
SqlDataSource1.InsertCommand = query;
SqlDataSource1.Insert();
//
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
}
12:
.
:
1. ?
2. ?
3. ' ?
4. , 䳿 - GridView?
5. , 䳿 - SqlDataSource?
4