Problem in retreving large data from excel to Gridview

asp.net , excel to gridview , csharp Alandur, India
  • 8 years ago
    Hi All, I want to retreive large data from excel to Gridview. I have an excel sheet with more than 200 rows. But when I binded to gridview i am getting only 15 rows. How could I solve this problem. Here is the code I have.. public void BindGridView() { OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\Documents and Settings\\Admin\\Clubs.xls;" + "Extended Properties=\"Excel 8.0;HDR=Yes\""); DBConnection.Open(); string SQLString = "SELECT * FROM [Sheet1$]"; OleDbCommand DBCommand = new OleDbCommand(SQLString, DBConnection); IDataReader DBReader = DBCommand.ExecuteReader(); gvList.DataSource = DBReader; gvList.DataBind(); } Should I Configure web.config to solve this problem.Can anyone help Please?? Thanks, Rajesh
  • 8 years ago
    Hi mr_rajesh86 ! never like this. i ever write a program to retrive more than 1000 rows from excel but nerver got any problems. Public Function ImportExcel(ByVal PrmPathExcelFile As String, ByVal DataGrid1 As DataGridView) Dim MyConnection As New System.Data.OleDb.OleDbConnection Try DataGrid1.Columns.Clear() ''''''' Fetch Data from Excel Dim DtSet As System.Data.DataSet Dim MyCommand As System.Data.OleDb.OleDbDataAdapter MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _ "data source='" & PrmPathExcelFile & " '; " & "Extended Properties=Excel 8.0;") ' Select the data from Sheet1 of the workbook. MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection) MyCommand.TableMappings.Add("Table", "Attendence") DtSet = New System.Data.DataSet MyCommand.Fill(DtSet) Dim i As Integer = DtSet.Tables(0).Rows.Count ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' DataGrid1.DataSource = DtSet.Tables(0) MyConnection.Close() Catch ex As Exception MyConnection.Close() End Try End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''ImportExcel(TxtPath.Text, DgWorksheet)'''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' try this and any problem post it again na thanks from Nimol Men

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The question of whether computers can think is just like the question of whether submarines can swim.” - Edsger W. Dijkstra