Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this page i import Excel to Sql table and Update that table then I bind that updated table in Gridview.

Alter PROC SP_Excel
(@ExcelName VARCHAR(100)
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$])'

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


protected void Button1_Click(object sender, EventArgs e)
        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand("SP_Excel", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@ExcelName", SqlDbType.VarChar).Value = FileUpload1.FileName.ToString();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        Button1.Visible = false;
        Button2.Visible = true;
        DataTable dt = new DataTable();
        GridView1.DataSource = dt;
        ViewState["dtList"] = dt;
        Response.Write("<script>alert('Table Imported Successfully');</script>");
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        GridView1.PageIndex = e.NewPageIndex;
Updated 25-Apr-13 21:17pm
RelicV 26-Apr-13 2:33am
Hi Saranya, I dont see a question here.. Please do add the issue that you are facing here. Thnx.!
Saranya Boopathi 26-Apr-13 2:36am
Hi Here I bind the data in GridView.But it not bind that is my issue
Karthik Harve 26-Apr-13 2:42am
did you debug the code ? does the datatable is getting filled with data ? Any exception ?
Saranya Boopathi 26-Apr-13 2:48am
No Exception
RelicV 26-Apr-13 2:49am
Are you getting the data in the DataTable 'dt' (check it in debugging)..? Could you please provide the front-end code (.aspx page) and also the Page_Load method.. Thnx.!
Saranya Boopathi 26-Apr-13 3:27am
In pageload i didnt wrote any code
Saranya Boopathi 26-Apr-13 4:38am
I got it ..I changed AutogenerateColumn as True

I dont know what things you tried in connection for excel..
I tried same as you require, you can check at...[^]

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900