简单数据库的调用

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication71._Default" %>



   


   


   

       
       
        
        
        
        
        
        

       

       
   

   


 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace WebApplication71
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string strconnection = "server=.;database=class;integrated security=true;";
            SqlConnection objconnection = new SqlConnection(strconnection);
            string sqlstr = "SELECT * FROM student WHERE number<5 order by number";
            SqlDataAdapter objadapter = new SqlDataAdapter(sqlstr ,objconnection );

            DataSet objdataset = new DataSet();
            objadapter.Fill(objdataset );
            objconnection.Close();
            dgclass.DataSource = objdataset;
            dgclass.DataBind();


        }
        protected void chkchanged(object sender, EventArgs e)
        {
            dgclass.Columns[1].Visible = chk1.Checked;
       
        }
    }
}


 

你可能感兴趣的:(简单数据库的调用)