本文介绍了在Asp.Net中执行Connectins我遇到错误,在执行Codi时我得到空参考异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
}
protected void BindGridView()
{
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("Select eid,ename,age from emp", con);
con.Open();
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
TextBox txt_name = new TextBox();
TextBox txt_age = new TextBox();
TextBox txt_id = new TextBox();
txt_id = (TextBox)GridView1.FooterRow.FindControl("txt_eid");
txt_name = (TextBox)GridView1.FooterRow.FindControl("txt_ename");
txt_age = (TextBox)GridView1.FooterRow.FindControl("txt_eage");
SqlCommand cmd = new SqlCommand("insert into emp(eid,ename,age)values('" + txt_id.Text + "','" + txt_name.Text + "','" + txt_age.Text + "')");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
BindGridView();
}
}
推荐答案
这篇关于在Asp.Net中执行Connectins我遇到错误,在执行Codi时我得到空参考异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!