在GridView中绑定数据 [英] Bind the data in GridView

查看:53
本文介绍了在GridView中绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此页面中,我将Excel导入到Sql表并更新该表,然后在Gridview中绑定更新的表。



SQL SP:

In this page i import Excel to Sql table and Update that table then I bind that updated table in Gridview.

SQL SP:

Alter PROC SP_Excel
(@ExcelName VARCHAR(100)
)
As
Begin
Declare @SQL VARCHAR(1000)
if OBJECT_ID('Table1') is not null
drop table Table1

SET @SQL= 'select * INTO Table1 from openrowset (''Microsoft.ACE.OLEDB.12.0'',''Excel 12.0;Database=d:\Sharedd\'+@ExcelName+''',[Sheet1$])'
EXEC(@SQL)

ALter table Table1 add  [UNO REEXECNAME] varchar(100),[UNO MOBILENO] varchar(20)

update table1 set [UNO REEXECNAME]=b.FName+b.MName+b.LName ,[UNO MOBILENO]=b.MobileNo
from LOln_LnDetails_h a join lgen_mktngagent b on a.LnRcvryExec=b.MktngAgentCode
right join Table1 c on a.LnNo=c.[UNO LOAN NUMBER]

select * from table1

End
















protected void Button1_Click(object sender, EventArgs e)
    {
        connectionstring();
        SqlConnection con = new SqlConnection(str);
        con.Open();
        SqlCommand cmd = new SqlCommand("SP_Excel", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@ExcelName", SqlDbType.VarChar).Value = FileUpload1.FileName.ToString();
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        con.Close();
        Button1.Visible = false;
        Button2.Visible = true;
        DataTable dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        ViewState["dtList"] = dt;
        Response.Write("<script>alert(''Table Imported Successfully'');</script>");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }

推荐答案

)'
EXEC @ SQL

ALter table Table1 add [UNO REEXECNAME] varchar 100 ),[UNO MOBILENO] varchar 20

update table1 set [UNO REEXECNAME] = b.FName + b.MName + b.LName,[UNO MOBILENO] = b.MobileNo
来自 LOln_LnDetails_h a join lgen_mktngagent b on a.LnRcvryExec = b.MktngAgentCode
right 加入表1 c a.LnNo = c。[UNO LOAN NUMBER ]

选择 * 来自 table1

< span class =code-keyword>结束
)' EXEC(@SQL) ALter table Table1 add [UNO REEXECNAME] varchar(100),[UNO MOBILENO] varchar(20) update table1 set [UNO REEXECNAME]=b.FName+b.MName+b.LName ,[UNO MOBILENO]=b.MobileNo from LOln_LnDetails_h a join lgen_mktngagent b on a.LnRcvryExec=b.MktngAgentCode right join Table1 c on a.LnNo=c.[UNO LOAN NUMBER] select * from table1 End
















protected void Button1_Click(object sender, EventArgs e)
    {
        connectionstring();
        SqlConnection con = new SqlConnection(str);
        con.Open();
        SqlCommand cmd = new SqlCommand("SP_Excel", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@ExcelName", SqlDbType.VarChar).Value = FileUpload1.FileName.ToString();
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        con.Close();
        Button1.Visible = false;
        Button2.Visible = true;
        DataTable dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        ViewState["dtList"] = dt;
        Response.Write("<script>alert(''Table Imported Successfully'');</script>");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }


我不知道你为excel尝试了什么东西..

我试过你需要的东西,您可以查看...

http://hemantrautela.blogspot.com/2012/09/database-connection-in-cnet-aspnet-with.html [ ^ ]



in你的代码与pagesize有什么关系。&我认为在GridView1_PageIndexChanging()事件中需要再次填充gridview1 ..在你的代码中你检查使用一步一步调试并检查DataTable中的数据dt
I dont know what things you tried in connection for excel..
I tried same as you require, you can check at...
http://hemantrautela.blogspot.com/2012/09/database-connection-in-cnet-aspnet-with.html[^]

in your code what about pagesize ..& i think in GridView1_PageIndexChanging()event require filled gridview1 again .. in your code you check using step by step debugging and check the data in DataTable dt


I got it ..I changed AutogenerateColumn as True


这篇关于在GridView中绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆