实验一 环境配置与sql操作
学号: 122055136 姓名:黄斌峻 日期:
1、实验目的:
熟悉VS2005开发环境,复习C#和SQL 2000相关操作
2、实验环境:
Windows XP、VS20005、SQL Server 2000
3、实验内容:
(1) 调试课本1.3节创建第一个ASP.Net2.0应用程序
(2) 利用控制台程序复习C#中选择结构、循环结构、类和对象的相关内容
(3) 利用VS2005分别创建WAP、智能设备和桌面应用程序
(4) 复习SQL 2000的相关操作
4、实验过程:
实验截图:
图一
代码详情
(2)利用控制台程序复习C#基础知识
a、主程序
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Student xuensheng = new Student();
xuensheng.displayPersonInfo();
xuensheng.playing("篮球");
xuensheng.study("ASP.NET");
jiuJiuChengFaBiao();
//选择结构、循环结构、类和对象的相关内容 Console.Write("亲输入一个数字判断大小"); string number=Console.ReadLine();
if (Convert.ToInt16(number) > 10)
{
Console.Write(number+"大于"+10); }
else{
Console.Write(number+"小于或等于"+10); }
Console.WriteLine();
}
public static void jiuJiuChengFaBiao() { for(int i=1;i<9;i++){
for(int j=1;j<=i;j++){
Console.Write(i+"*"+j+"="+(i*j)+" ");
}
Console.WriteLine();
}
}
}
}
b、几何类
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Student
{
public string name;
public string number;
public int age;
public Student(string name,string number,int age) { this.name = name;
this.age = age;
this.number = number;
图二
图三
5、实验总结:
(1)通过此次实验,对C#中的选择、循环、类和对象等相关内容进行了复习,发现了自己的不足,通过认真复习,为今后ASP.NET网站开发打下一定基础;
(2)学会了如何创建一个网站,并对网站中的标签和内容有了较为深刻的理解,能够自己创建一个网站,并进行调试;
第二篇:net实验报告
本文由德约杲杲贡献doc文档可能在WAP端浏览体验不佳。建议您优先选择TXT,或下载源文件到本机查看。一、实验目的: 实验目的:1.掌握 NET 程序设计方法。 2.理解并运行 C#语言操作语言。 3. 掌握 Gridview,DetailView,SqlDatasource,SqlDatareader 等控件。 4. 培养学生独立学习思索以及组织管理能力二、实验内容: 实验内容:1.对建立电子商务网站需要使用的技术,工具进行分析。 2.对购物网站前后台操作过程中所使用的知识点进行分析。 3.书写整个数据库资料表字段的含义及数据类型。 4.画出购物车流程图三、软件运行截图: 软件运行截图:1.软件名称:Visual Studio 20052.软件名称:SQL Server 2000 (1)企业管理器:(2)查询分析器:四、软件设计文档,代码及对代码进行说明: 软件设计文档,代码及对代码进行说明: 设计文档1、数据库的建立(企业管理器、查询分析器) 数据库的建立(企业管理器、查询分析器) 的建立2、网站代码截图: 网站代码截图 1)登陆页面:Login.aspx 代码: 代码: 登錄 用戶 名: * 密 碼: * Login.aspx.cs 代码: Login.aspx.cs 代码: public partial class Login : System.Web.UI.Page { private string uid; private string pwd; private clsUser cUser = new clsUser(); protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { string url = Request.QueryString["url"]; uid = UserName.Text.Trim(); pwd = Password.Text.Trim(); if (string.IsNullOrEmpty(url)){ url="Manage_Users.aspx";}clsUser.UserLoginValid(uid, pwd, url); } }界面截图: 界面截图:2)用户注销页面:Logout.aspx 代码:内容为空 代码: Logout.aspx.cs 代码: 代码: public partial class admin_Logout : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Session["user"] = null; Session.Abandon(); Response.Redirect("login.aspx"); } }界面截图: 界面截图:3)用户管理页面:ManagerUser.aspx 代码: 代码: <RowStyle BackColor="#EFF3FB" /> <Columns> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" />" DeleteCommand="DELETE FROM t_user WHERE (userid = @userid)" SelectCommand="SELECT * FROM [t_user]"> <DeleteParameters> </DeleteParameters> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <Fields> </Fields> <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" /> " InsertCommand="INSERT INTO t_user(userid, userpwd, username, roleid) VALUES (@userid, @userpwd, @username, @roleid)" SelectCommand="SELECT [userid], [userpwd], [username], [roleid] F
ROM [t_user] WHERE ([userid] = @userid)" UpdateCommand="UPDATE t_user SET userpwd = @userpwd, username = @username, roleid = @roleid WHERE (userid = @userid)"> ManagerUser.aspx.cs 代码: 代码: public partial class admin_Manage_Users : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string rolename = ""; clsUser u = new clsUser(); u = (clsUser)HttpContext.Current.Session["user"]; if (u == null) { } } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e) { } protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { GridView1.SelectedIndex = -1; GridView1.DataBind(); } protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e) { } } 设计界面截图: 设计界面截图: 界面截图 GridView1.SelectedIndex = -1; GridView1.DataBind(); GridView1.SelectedIndex = -1; GridView1.DataBind(); DetailsView1.ChangeMode(DetailsViewMode.Edit); Response.Write("你沒有登入!"); Response.Redirect("Login.aspx?url=" + Server.UrlEncode(Request.RawUrl));4)用户权限页面:UsersRight.aspx 代码: 代码: <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#EFF3FB" /> <Columns> </Columns> <EditRowStyle BackColor="#2461BF" /> " DeleteCommand="DELETE FROM x_rightname WHERE (roleid = @roleid)" SelectCommand="SELECT * FROM [x_rightname]"> <DeleteParameters> </DeleteParameters> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <Fields> </Fields> <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" /> " InsertCommand="INSERT INTO x_rightname(rolename, rolenamech) VALUES (@rolename, @rolenamech)" SelectCommand="SELECT [roleid], [rolename], [rolenamech] FROM [x_rightname] WHERE ([roleid] = @roleid)" UpdateCommand="UPDATE x_rightname SET rolename = @rolename, rolenamech = @rolenamech"> UsersRight.aspx.cs 代码:同上 代码:界面截图: 界面截图:5)新闻种类网页:ManagerArticles.aspx 代码 <RowStyle BackColor="#EFF3FB" /> <Columns> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> " DeleteCommand="delete [ArticleTypes] where id=@id" SelectCommand="SELECT [ID], [TheName], [Description] FROM [ArticleTypes]"> <DeleteParameters> </DeleteParameters> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <Fields> </Fields> <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" /> " InsertCommand="INSERT INTO ArticleTypes(TheName, Description) VALUES (@TheName, @Description)" SelectCommand="SELECT [ID], [TheName], [Description] FROM [ArticleTypes] WHERE ([ID] = @ID)" UpdateCommand="UPDATE ArticleTypes S
ET TheName = @TheName, Description = @Description WHERE (ID = @id)"> ManagerArticles.aspx.cs 代码:同上 代码: 设计界面截图: 设计界面截图:运行界面截图: 运行界面截图:6)新闻小类网页: 代码: 代码: 新闻大类:请选择 " SelectCommand="SELECT [ID], [TheName] FROM [ArticleTypes]"> <RowStyle BackColor="#EFF3FB" /> <Columns> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> " DeleteCommand="DELETE FROM ArticleCategories WHERE (CategoryID = @categoryid)" SelectCommand="SELECT ArticleCategories.CategoryID, ArticleCategories.Title, ArticleCategories.Description, ArticleCategories.TypeId, ArticleTypes.TheName FROM ArticleCategories INNER JOIN ArticleTypes ON ArticleCategories.TypeId = ArticleTypes.ID WHERE (ArticleCategories.TypeId = @TypeId)"> <DeleteParameters> </DeleteParameters> <Fields> </Fields> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" /> " InsertCommand="INSERT INTO ArticleCategories(Title, Description, TypeId) VALUES (@Title, @Description, @TypeId)" SelectCommand="SELECT [CategoryID], [Title], [Description], [TypeId] FROM [ArticleCategories] WHERE ([CategoryID] = @CategoryID)" UpdateCommand="UPDATE ArticleCategories SET Title = @Title, Description = @Description, TypeId= @TypeId WHERE (CategoryID = @categoryid)"> 代码: 代码:同上 设计界面截图: 设计界面截图:运行界面截图: 运行界面截图:7)新闻管理网页:代码: 代码: 新闻大类: 新闻小类: 请选择 " SelectCommand="SELECT [CategoryID], [Title] FROM [ArticleCategories] WHERE ([TypeId] = @TypeId2)"> " SelectCommand="SELECT [ID], [TheName] FROM [ArticleTypes]"> <RowStyle BackColor="#EFF3FB" /> <Columns> </Columns><FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> " DeleteCommand="DELETE FROM Articles WHERE (ArticleID = @Articleid)" SelectCommand="SELECT [ArticleID], [Title], [Body], [CategoryID], [ViewCount], [ReleaseDate] FROM [Articles] WHERE ([CategoryID] = @CategoryID)"> <DeleteParameters> </DeleteParameters> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <Fields> <EditItemTemplate>' Width="500px"></EditItemTemplate> ' Width="500px"> '> <EditItemTemplate> ' TextMode="MultiLine" Height="400px" Width="600px" ></EditItemTemplate> ' TextMode="MultiLine" Height="400px" Width="600px"> '> </Fields> <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" /> onString="<%$ ConnectionStrings:EbussinessConnectionString %>" InsertCommand="INSERT INTO Articles(Title, Body, CategoryID) VALUES (@Title, @Body,@CategoryID)" SelectCommand="SELEC
T [ArticleID], [Title], [Body], [CategoryID], [ViewCount], [ReleaseDate] FROM [Articles] WHERE ([ArticleID] = @ArticleID)" UpdateCommand="UPDATE Articles SET Title = @Title, Body = @Body, CategoryID = @CategoryID WHERE 代码: 代码:同上 设计界面截图: 设计界面截图:运行界面截图: 运行界面截图:8)商品种类网页:ProductsCategory.aspx 代码: 代码: <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><Columns> <asp:BoundField DataField="CategoryID" HeaderText="商品种类编号" InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" /> </Columns> <RowStyle BackColor="#EFF3FB" /> <EditRowStyle BackColor="#2461BF" /> " DeleteCommand="delete [ProductCategories] where categoryid=@categoryid" SelectCommand="SELECT * FROM [ProductCategories]"><DeleteParameters> <leteParameters> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /><RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <Fields> </Fields> <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" /> " InsertCommand="INSERT INTO ProductCategories(CategoryName, Description) VALUES (@CategoryName, @Description)" SelectCommand="SELECT CategoryID, CategoryName, Description FROM ProductCategories WHERE (CategoryID = @categoryid)" UpdateCommand="UPDATE ProductCategories SET CategoryName = @CategoryName, Description = @Description WHERE (CategoryID = @categoryid)"> ProductsCategory.aspx.cs 代码: 代码: public partial class admin_ManageProductcategories : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) {DetailsView1.ChangeMode(DetailsViewMode.Edit); } protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e) { GridView1.SelectedIndex = -1; GridView1.DataBind(); } protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e) { GridView1.SelectedIndex = -1;GridView1.DataBind(); } protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e) { } } 设计界面截图: 设计界面截图: 界面截图 GridView1.SelectedIndex = -1; GridView1.DataBind();运行界面截图: 运行界面截图:9)商品管理网页:ManagementProducts2.aspx 代码: 代码: 选择商品种类: "SelectCommand="SELECT [CategoryID], [CategoryName] FROM [ProductCategories]"> <Columns> </Columns> <RowStyle BackColor="#EFF3FB" /> <EditRowStyle BackColor="#2461BF" /> onString="<%$ ConnectionStrings:EbussinessConnectionString %>" DeleteCommand="DELETE FROM Products WHERE (ProductID = @productid)" nd="SELECT ProductID, ProductName, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products WHERE (CategoryID = @categoryid)"> <DeleteParameters> </DeleteParameters> <FooterStyle BackColor
="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <Fields> </Fields> <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" /> " InsertCommand="INSERT INTO Products(ProductName, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued) VALUES (@ProductName, @CategoryID, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @UnitsOnOrder, @ReorderLevel, @Discontinued)" SelectCommand="SELECT ProductID, ProductName, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products WHERE (ProductID = @productid)" UpdateCommand="UPDATE Products SET ProductName = @ProductName, CategoryID = @CategoryID, UnitPrice = @UnitPrice, UnitsInStock = @UnitsInStock, ReorderLevel = @ReorderLevel, UnitsOnOrder = @UnitsOnOrder, QuantityPerUnit = @QuantityPerUnit, Discontinued = @Discontinued WHERE (ProductID = @productid)"> 界面截图: 界面截图:11)购物车网页: Default.aspx 代码: 代码: <RowStyle BackColor="#DEDFDE" ForeColor="Black" /><Columns> </Columns> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> " SelectCommand="SELECT Products.*, ProductCategories.CategoryName FROM Products INNER JOIN ProductCategories ON Products.CategoryID = ProductCategories.CategoryID"> 界面截图: 界面截图:12)结账网页:View_ShoppingCart..aspx 代码: 代码: <Columns> </ItemTemplate> " Text="删除"> </Columns> <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> 界面截图: 界面截图:13)结账后网页:Checkout.aspx 代码: 代码: 一些信息 界面截图: 界面截图:五、实验总结: 实验总结:通过本次实验,我基本掌握了.NET 程序设计方法,可以运用 C#语言操作数 据库。掌握了 Gridview, DetailView, SqlDatasource, SqlDatareader 等控件的运用方法。 实验过程中,我基本上学会了应用 C#语言制作网页和使用 Visual Studio 2005 这种 软件。后台数据库的建立和前台的应用的建立,使我对.NET 有了更深刻的认识和对软件更 加熟练的应用, 当然,在实验过程中,我还遇到了很多麻烦。 例如: 1.在建立 Manage_user 的过程中,页面打开时出现了问题。后来查其原因,才 发现,是由于在建立数据源的过程中,给 INSERT 编代码时多了一个空格,即 INSERT INTO [t_user] ([userid], [userpwd], [username], [roleid], [lastlogindate]) VALUES (@userid, @userpwd, @username, @roleid, @lastlogindate)代码中@ lastlogindate 的@前多了一个空格,这么小的一个错误,就导致了运 行的不成功。但是终于找到了,解决了问题。 2.此外,在接下来运行作了半截的实验时,发现在浏览器中查看不成功。原来 是没有及时配置数据源。配置成功后,可以继
续编辑。总的来说,这次试验我获益良多。不仅在技术上有了相当水平的提高,在知识水平上有 了一定的增长,而且在查找和解决问题的能力上有了更深远的进步。此外,衷心的感谢在实 验过程中老师、同学对我的知道与帮助。