asp.net和数据库的有关代码

 

 protected void btntianjia_Click(object sender, EventArgs e)
    {
        string str;
        str = "您提供的信息是:Sno='" + Sno.Text+"'and Sname="+"'Sname .Text'";
        if (Sex.Checked == true)     //RadioButton中Groupname=“sex”属性值相同
        {
            str = str + "性别:男"; 
        }
        else
            str = str + "性别:女";
        str = str +"院系是:sdept='"+ ddlsdept.SelectedItem.Text+"'";
       warning .Text = str;
    }

//绑定

 if (!IsPostBack)
        {
        //绑定课程号
            for (int i = 1; i < 10; i++)
                ddlcno.Items.Add(i.ToString());

        }

//日期查询--日查询

 protected void Button1_Click(object sender, EventArgs e)
    {
       
        DataSet ds = (DataSet)ViewState["ds"];
        DataView dv = new DataView(ds.Tables[0]);
       
        dv.RowFilter = "日期='" + Convert.ToDateTime(txtDate.Value.ToString()).ToString("yyyy/MM/dd")+"'";

        gvWeather.DataSource = Common.Pager.GetDataSource(AspNetPager1, dv.ToTable());
        AspNetPager1.RecordCount = dv.ToTable().Rows.Count;
        gvWeather.DataBind();
        }

//日期查询--月查询

protected void Button1_Click1(object sender, EventArgs e)
    {
        DataSet ds = (DataSet)ViewState["ds"];
        DataView dv = new DataView(ds.Tables[0]);

        dv.RowFilter = "年份='" + Convert.ToDateTime(txtDate.Value.ToString()).Year.ToString() + "' and 月份="+Convert.ToDateTime(txtDate.Value.ToString()).Month.ToString();
        gvWeather.DataSource = Common.Pager.GetDataSource(AspNetPager1, dv.ToTable());
        AspNetPager1.RecordCount = dv.ToTable().Rows.Count;
        gvWeather.DataBind();

//日期查询--旬查询

 protected void btnXunQuery_Click(object sender, EventArgs e)
    {
        DataSet ds = (DataSet)ViewState["ds"];
        DataView dv = new DataView(ds.Tables[0]);

        dv.RowFilter = "年份='" + ddlYear.SelectedItem.ToString() + "' and 第几旬=" + ddlXun.SelectedItem.ToString();

      //分页
        gvWeather.DataSource = Common.Pager.GetDataSource(AspNetPager1, dv.ToTable());
        AspNetPager1.RecordCount = dv.ToTable().Rows.Count;
        gvWeather.DataBind();
    }

//日期查询——日查询管理

protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable dt = (DataTable)ViewState["WeatherInfo"];

        DataView dv = dt.DefaultView;

        dv.RowFilter = "Date='"+Convert.ToDateTime(txtDate.Text).ToString()+"'";

        gvWeatherInfo.DataSource = Common.Pager.GetDataSource(AspNetPager1, dv.ToTable());
        AspNetPager1.RecordCount = dv.ToTable().Rows.Count;
        gvWeatherInfo.DataKeyNames = new string[] { "Guid" };
        gvWeatherInfo.DataBind();     
    }

//日期查询——旬查询管理

 protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = (DataSet)ViewState["ds"];
        DataView dv = new DataView(ds.Tables[0]);

        dv.RowFilter = "Year='" + ddlYear.SelectedItem.ToString() + "' and Type=" + ddlXun.SelectedItem.ToString();
        gvWeather.DataSource = Common.Pager.GetDataSource(AspNetPager1, dv.ToTable());
        AspNetPager1.RecordCount = dv.ToTable().Rows.Count;
        gvWeather.DataBind();

}

//连接数据库

<connectionStrings>
    <add name="Connection" connectionString="server=.;database=Student;uid=sa;pwd=123456;" providerName="System.Data.SqlClient" />
  </connectionStrings>

//删除记录

protected void gvWeatherInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        string guid = gvWeather.DataKeys[e.RowIndex].Value.ToString();

        SqlConnection connection = new SqlConnection(conn);
        string SQLString = "delete WeatherInfo_Xun where Guid='"+guid+"'";
        SqlCommand cmd = new SqlCommand(SQLString, connection);
        try
        {
            connection.Open();
            int rows = cmd.ExecuteNonQuery();

        }
        catch (System.Data.SqlClient.SqlException E)
        {
            connection.Close();
            throw new Exception(E.Message);
        }   
             Page.ClientScript.RegisterStartupScript(typeof(string), "", "alert('删除成功!');", true);
               }

//修改记录

protected void gvWeatherInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string guid = gvWeather.DataKeys[e.RowIndex].Value.ToString();
        Common.BLL.WeatherInfo_Xun bWeather = new Common.BLL.WeatherInfo_Xun();
        Common.Model.WeatherInfo_Xun mWeather = bWeather.GetModel(new Guid(guid));
        string stadiaCode = mWeather.StadiaCode;
        Response.Redirect("../StationImportent/ModifyWeatherInfoX.aspx?Guid=" + guid + "&StadiaCode=" + stadiaCode);
    }

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值