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.

SQL SP:
SQL
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();
    }
Posted
Updated 25-Apr-13 21:17pm
v2
Comments
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...
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
   

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