⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代码
💻 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 System.Data.SqlClient;
using System.Management;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)//首次执行页面时
        {
            GridViewBind();//绑定自定义方法GridViewBind
            SqlConnection con = new SqlConnection("Server=(Local);user id=sa;pwd=;DataBase=mrdb");
            con.Open();
            //获取数据库中的所有用户表的表名
            string systable="use mrdb SELECT * FROM mrdb.dbo.sysobjects WHERE xtype='U' AND STATUS>=0";
            SqlDataAdapter ada = new SqlDataAdapter(systable, con);
            DataSet ds = new DataSet();
            ada.Fill(ds);
            DropDownList1.DataSource = ds;
            DropDownList1.DataTextField = "name";
            DropDownList1.DataValueField = "name";
            DropDownList1.DataBind();
            
        }
    }
    public void GridViewBind()//绑定GridView控件的自定义方法
    {
        SqlConnection con = new SqlConnection("Server=(Local);user id=sa;pwd=;DataBase=mrdb");
        con.Open();
        SqlDataAdapter ada = new SqlDataAdapter("select * from tb_13", con);
        DataSet ds = new DataSet();
        ada.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
        
    }
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            SqlConnection con = new SqlConnection("Server=(Local);user id=sa;pwd=;DataBase=mrdb");
            con.Open();
            SqlCommand com = new SqlCommand("delete " + DropDownList1.Text + " from " + DropDownList1.Text + "", con);
            com.ExecuteNonQuery();
            GridViewBind();
            Response.Write("<script language=javascript>alert('删除成功!')</script>");
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
         try
        {
        SqlConnection con = new SqlConnection("Server=(Local);user id=sa;pwd=;DataBase=mrdb");
        con.Open();
        SqlDataAdapter ada = new SqlDataAdapter("select * from "+DropDownList1.SelectedValue+" ", con);
        DataSet ds = new DataSet();
        ada.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message.ToString());
    }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -