.net实验报告2

时间:2024.3.31

河南城建学院

《--网站建设技术--》实验报告

实验名称:用户名密码登录+切图制作网站    专业班级:  软件工程    

姓名:   吴春龙                           学号:  084413147     

实 验 日 期 :  20##年 9月 22日

 软件环境:Windows xp,开发工具:Visual Studio 20##/20##、SQL2005.

一、实验目的

1.利用所学知识建设网站与SQL server 2008数据库进行连接用户登录跳转网页;

2.添加图片到网站设计网页。

二、实验过程及内容

实验内容:

1.       运用软件Visual Studio 2010组织登录框架,编写代码。建设两个空网站进行编码,实现网页的跳转登录与用户名密码的重置。

2.       利用fireworks软件进行剪切图片保存到文件夹,再运用HTML网页制作技术设计添加到网站。

实验过程:

1.打开Visual Studio 2010建设空网站进行编写代码;

2.打开数据库SQL server 2008建立数据库与表,在表中添加数据;

3.把数据库与Visual Studio 2010建设的网站进行连接调试运行。

4.在Visual Studio 2010中重新建设网站进行设计,并添加图片到网页。

三、实验数据

1.网页用户登陆截图

图1 登录界面

图2 登录成功界面

部分代码:public partial class Default2 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        string s = "";

        string t = "";

        s = TextBox1.Text;

        t = TextBox2.Text;

        SqlConnection conn = new SqlConnection("server=.;database=text;Trusted_connection=yes");

        conn.Open();

        SqlCommand cmd = new SqlCommand();

        cmd.CommandText = "select * from Table_1 where name='" + s + "'and password='" + t + "'";

        cmd.Connection = conn;

        SqlDataReader sdr = cmd.ExecuteReader();

        if (sdr.Read())

        {

            Response.Redirect("Default2.aspx");

        }

        else

        {

            Response.Redirect("Default.aspx");

        }

        sdr.Close();

        conn.Close();

    }

    protected void Button2_Click(object sender, EventArgs e)

    {

        TextBox1.Text = "";

        TextBox2.Text = "";

    }

}

2.网页添加图片制作截图

图3 网页添加图片

  部分代码:<html xmlns="http://www.w3.org/1999/xhtml">

  <head runat="server">

      <title></title>

      <style type="text/css">

        .style1

        {

            width: 220px;

            height: 120px;

        }

        .style2

        {

            width: 220px;

            height: 120px;

         }

        .style3

        {

            width: 220px;

            height: 120px;

         }

        .style4

        {

            width: 220px;

            height: 120px;

         }

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <table width="10" cellpadding=0 cellspacing =0 align=center>

    <tr>

    <td>

        <img alt="" class="style1" src="images/1.jpg" /></td>

    <td>

        <img alt="" class="style2" src="images/2.jpg" /></td>

    <td>

        <img alt="" class="style3" src="images/3.jpg" /></td>

    <td>

        <img alt="" class="style4" src="images/4.jpg" /></td>

    </tr>

    </table>

   

    </div>

    </form>

</body>

</html>

四、出现问题及解决方案

1.在编写代码的工程中出现代码书写错误,在运行的过程中发现及时改正。

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>&nbsp; <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]">&nbsp;<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"> &nbsp; 界面截图: 界面截图: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.此外,在接下来运行作了半截的实验时,发现在浏览器中查看不成功。原来 是没有及时配置数据源。配置成功后,可以继

续编辑。总的来说,这次试验我获益良多。不仅在技术上有了相当水平的提高,在知识水平上有 了一定的增长,而且在查找和解决问题的能力上有了更深远的进步。此外,衷心的感谢在实 验过程中老师、同学对我的知道与帮助。

更多相关推荐:
.Net实验报告2

实验报告学院系名称计算机与通信工程学院第1页共9页第2页共9页第3页共9页第4页共9页第5页共9页第6页共9页第7页共9页第8页共9页第9页共9页

.net实验报告

实验一环境配置与sql操作学号姓名日期20xx年11月251实验目的熟悉VS20xx开发环境复习C和SQL20xx相关操作2实验环境WindowsXPVS20xx5SQLServer20xx3实验内容1调试课本...

NETWeb实验报告

NET上机实验报告WEB数据库应用程序设计姓名杨森班级计103学号10101020xx2实验成绩一实验目的通过对aspnet学习完成一个简单的新闻管理系统系统可以实现对记录的选择编辑删除排序翻页效果二实验内容1...

.net实验报告

燕山大学Net程序设计实验报告学院信息科学与工程学院年级专业08级计算机科学2班指导教师崔永强学生学号080104010108学生姓名吴英梅提交日期20xx0513实验一实现登录界面显示用户名字实验设计1编写l...

.net实验报告

.net实验报告,内容附图。

C# .net实验报告

目录一实验目的2二实验要求2三实验内容2任务1判断每个输入的数是否可被35和7整除并将整除状态输出2任务2练习使用forwhiledowhileforeachin等循环语句3任务3绘图输出yasincxb3四实...

.net实验报告

封面设计贾丽地址中国河北省秦皇岛市河北大街438号邮编066004电话03358057068传真03358057068网址httpjwc实验一网页制作及服务组件的使用一实验目的实现个人注册页面的制作和显示注册页...

.net课程设计实验报告

实验目的通过软件开发的实践训练进一步了解软件工程的方法和技术提高软件开发的实际能力培养工程设计能力和综合分析解决问题的能力具体如下1学习和实践面向对象的系统分析与设计编码和测试方面的知识2熟悉自动化的软件开发工...

ASP. net实验报告

20xx13137028陈旻实计科1301ASPNET网站开发实验指导老师柯鹏学院计算机学院学生姓名陈旻实学生学号20xx13137028班级计科1301班20xx13137028陈旻实计科1301实验1EFl...

.net实验报告一

实验一环境配置与sql操作学号1220xx136姓名黄斌峻日期1实验目的熟悉VS20xx开发环境复习C和SQL20xx相关操作2实验环境WindowsXPVS20xx5SQLServer20xx3实验内容1调试...

.net实验报告

实验一1实验要求基本的网页制作2目的掌握HTML与ASPX基础联系制作基本的ASPNET网页使用VS20xx提供的导航控件并结合站点地图制作基本的导航栏3工程截图工程运行效果图4关键代码Bigheadaspx关...

.net实验报告

实验一环境配置与sql操作学号姓名日期1实验目的熟悉VS20xx开发环境复习C和SQL20xx相关操作2实验环境WindowsXPVS20xx5SQLServer20xx3实验内容1调试课本13节创建第一个AS...

.net实验报告(25篇)