工程范例

   

类库文件(DBoper.cs):

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DBManage
{
    public class DBoper
    {
        public static DataSet getCustomers(string ContactTitle, string Conn)
        {
            string str = "select * from Customers where ContactTitle=@ContactTitle";
            SqlConnection sqlConn = new SqlConnection(Conn);
            sqlConn.Open();
            SqlCommand sqlCmd = new SqlCommand(str, sqlConn);
            SqlParameter ConTitle = new SqlParameter("@ContactTitle",SqlDbType.NVarChar,20);
            ConTitle.Value = ContactTitle;
            sqlCmd.Parameters.Add(ConTitle);
            SqlDataAdapter sqlAdpor = new SqlDataAdapter(sqlCmd);
            DataSet ds = new DataSet();
            sqlAdpor.Fill(ds,"Customers");
            sqlConn.Close();
            return ds;

        }
    }
}

首页文件((Default.aspx):

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="test.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#E3EAEB" />
            <EditRowStyle BackColor="#7C6F57" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
   
    </div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    </form>
</body>
</html>

后台文件(Default.aspx,cs):

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBManage;
using System.Configuration;

namespace test
{

    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string contitle;
            string Conn = ConfigurationManager.AppSettings["sqlConnectionString"];
            contitle = TextBox1.Text;
            GridView1.DataSource= DBoper.getCustomers(contitle, Conn);
            GridView1.DataBind();
        }
    }
}

过程:先编写类库,然后将其编译,生成dll文件,并在网页工程中添加引用,最后在工程中调用

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值