Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7081925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:58:55+00:00 2026-05-28T06:58:55+00:00

Dim flag As Boolean = True Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName) Dim fileExtension

  • 0
Dim flag As Boolean = True

Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)

Dim fileExtension As String = Path.GetExtension(FileUpload1.PostedFile.FileName)

Dim fileLocation As String = Server.MapPath("~/Upload/" & fileName)

'Check whether file extension is xls or xslx
If fileExtension = ".xls" Then
    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fileLocation & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2"""
ElseIf fileExtension = ".xlsx" Then
    connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & fileLocation & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2"""
End If

'Create OleDB Connection and OleDb Command

Dim con As New OleDbConnection(connectionString)
Dim cmd As New OleDbCommand()
cmd.CommandType = System.Data.CommandType.Text
cmd.Connection = con
Dim dAdapter As New OleDbDataAdapter(cmd)
Dim dtExcelRecords As New DataTable()
con.Open()
Dim dtExcelSheetName As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim getExcelSheetName As String = dtExcelSheetName.Rows(0)("Table_Name").ToString()
cmd.CommandText = "SELECT * FROM [" & getExcelSheetName & "]"
dAdapter.SelectCommand = cmd
dAdapter.Fill(dtExcelRecords)
con.Close()

Dim row As DataRow
For Each row In dtExcelRecords.Rows
    If Include.ConvertDbNullToEmpyString(row(2)) = "" Then
        MsgBox("Error in saving!")
        Exit For

    End If
    MsgBox(row(0) & " " & row(1) & " " & row(2) & " " & row(3))
Next


GridView1.DataSource = dtExcelRecords

GridView1.DataBind()
ViewState("file") = dtExcelRecords


Dim dataSet As DataSet = New DataSet("dataSet")
dataSet.Tables.Add(dtExcelRecords)
'' Display the DataSet contents as XML.
Console.WriteLine(dataSet.Tables(0).DataSet.GetXml())

I had code which use to upload file excel into datatable and show at gridview.

After show at gridview, the excel value which has been convert into datatable and showed at gridview will be saved to database.

My problem :

Dim row As DataRow
For Each row In dtExcelRecords.Rows
    If Include.ConvertDbNullToEmpyString(row(2)) = "" Then
        MsgBox("Error in saving!")
        Exit For
    End If
    MsgBox(row(0) & " " & row(1) & " " & row(2) & " " & row(3))
Next

that was code to get the row value.

But how to set datatable with new data row?

If I had null value in row 2, I wanted proses input data to datatable will stoped!
And showing with new value from datarow value into gridView.

————————————– EDIT ———————————-

example :

upload file excel :

col1 —- col2 —- col3 —- col4

tes1 —- test1 —- test1 —- test1

tes2 —- test2 —- —- test2

tes3 —- test3 —- test3 —- test3

tes4 —- test4 —- —- test4

and the result at gridview must like this :

col1 —- col2 —- col3 —- col4

tes1 —- test1 —- test1 —- test1

tes3 —- test3 —- test3 —- test3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:58:56+00:00Added an answer on May 28, 2026 at 6:58 am

    Try,

                    Dim dtData As DataTable
                    dtData = New DataTable
                    dtData.Columns.Add("Row0")
                    dtData.Columns.Add("Row1")
                    dtData.Columns.Add("Row2")
                    dtData.Columns.Add("Row3")
    
                    Dim row As DataRow
                    For Each row In dtExcelRecords.Rows
                        If Include.ConvertDbNullToEmpyString(row(2)) = "" Then
                            MsgBox("Error in saving!")
                            Exit For 'or exit Sub
                        End If
                        Dim dr As DataRow = dtData.NewRow
    
                        dr("Row0") = row(0)
                        dr("Row1") = row(1)
                        dr("Row2") = row(2)
                        dr("Row3") = row(3)
    
                        dtData.Rows.Add(dr) 'Add this line
    
                    Next
    
                    'Bind dtData to gridview
                    'Save data in dtData to database
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

dim dataType as String toolTip=Marks And Number[String] I want to get the [String] alone.
Consider: Dim line As String Using readFile As New StreamReader(SalesUpdateFile) While (line = readFile.ReadLine)
Here is the sample: Dim TestString As String = Hello, & Chr(0) & World
Dim usersInRole As String() = Roles.GetUsersInRole(HR_Base_Role) Dim Myusers As New MembershipUserCollection For Each UserName
Dim str as string = <request id=value1 type=value2>value3</request> How could select the values as
Dim goodCustObjList As New List(Of CustomerObj) goodCustObjList = DataBLLModule.GetCustomerRecordList(String.Empty) Dim custList = From t
Dim myString As String = 1234567890 Dim Part As String = Part = myString.Substring(2,
Dim x = GetType(List(Of )) 'valid statement Dim list As New List(Of String) Now
Dim strTest(recordSet.Count)() As String While index < recordSet.Count strTest(index)(recordset.item(index).getvalue(0).tostring, recordset.item(index).getvalue(0).tostring, recordset.item(index).getvalue(0).tostring) index +=1 End
Dim str as String str = 30 40 50 60 I want to count

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.