asp dot net中的gridview [英] gridview in asp dot net
问题描述
我编写的代码如下所示可以运行我的程序bur在更新时无法在gridview中获取数据。有人可以帮助我吗?
i write the code as such as in below can run my program bur can't get data in gridview while updating..can anybody help me?
我的cs代码
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web ;
$
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Data;
使用System.Data.SqlClient;
使用System.Xml;
使用System.Xml.Linq;
使用System。配置;
$
公共部分类Gridview_using_database:System.Web.UI.Page
{
  SqlConnection con = new SqlConnection();
  DataTable dt;
  SqlDataAdapter adp;
  protected void Page_Load(object sender,EventArgs e)
  {
$
  }¥b $ b   protected void SqlDataSource1_Selecting(object sender,SqlDataSourceSelectingEventArgs e)
  {
$
  }
  protected void SubmitOnclick_data(object sender,EventArgs e)
  {
      con.ConnectionString = ConfigurationManager.ConnectionStrings [" Con"]。ConnectionString;
      con.Open();
      if(con.State!= ConnectionState.Open)
      {
          con.Open();
          SqlCommand cmd = new SqlCommand(" INSERTDATA",con);
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.Add(" @ SERIALNUMBER",SqlDbType.Int).Value = TextBox2.Text;
          cmd.Parameters.Add(" @ NAME",SqlDbType.VarChar,20).Value = TextBox1.Text;
          cmd.Parameters.Add(" @ QUALIFICATION",SqlDbType.VarChar,20).Value = TextBox3.Text;
          cmd.Parameters.Add(" @ NATIONALITY",SqlDbType.VarChar,20).Value = TextBox4.Text;
          cmd.Parameters.Add(" @CITY",SqlDbType.VarChar,20).Value = TextBox5.Text;
          cmd.Parameters.Add(" @ ADDRESS",SqlDbType.VarChar,20).Value = TextBox6.Text;
          cmd.ExecuteNonQuery();
$
          SqlCommand test = new SqlCommand(" select * from anjana" con);
      adp = new SqlDataAdapter();
      adp.Fill(DT);    
      GridView1.DataSource = dt;
      GridView1.DataBind();
      con.Close();
      }
  }¥b $ b }
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.Xml;
using System.Xml.Linq;
using System.Configuration;
public partial class Gridview_using_database : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
DataTable dt;
SqlDataAdapter adp;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
protected void SubmitOnclick_data(object sender, EventArgs e)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;
con.Open();
if (con.State != ConnectionState.Open)
{
con.Open();
SqlCommand cmd = new SqlCommand("INSERTDATA", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@SERIALNUMBER", SqlDbType.Int).Value = TextBox2.Text;
cmd.Parameters.Add("@NAME", SqlDbType.VarChar, 20).Value = TextBox1.Text;
cmd.Parameters.Add("@QUALIFICATION", SqlDbType.VarChar, 20).Value = TextBox3.Text;
cmd.Parameters.Add("@NATIONALITY", SqlDbType.VarChar, 20).Value = TextBox4.Text;
cmd.Parameters.Add("@CITY ",SqlDbType.VarChar, 20).Value = TextBox5.Text;
cmd.Parameters.Add("@ADDRESS", SqlDbType.VarChar, 20).Value = TextBox6.Text;
cmd.ExecuteNonQuery();
SqlCommand test = new SqlCommand("select * from anjana", con);
adp=new SqlDataAdapter();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
}
}
我的aspx代码。
Sumathi
推荐答案
ASP.NET论坛 http://forums.asp.net 是这类问题的更好地方
The ASP.NET forums http://forums.asp.net is the better place for such questions
这篇关于asp dot net中的gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!