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 8970589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:44:50+00:00 2026-06-15T17:44:50+00:00

This is pradeep This is the code of the excel uploading to sql database

  • 0

This is pradeep

This is the code of the excel uploading to sql database

protected void btnupload_Click ( object sender, EventArgs e )
{

  //string name = ddloutlet.SelectedValue.ToString ();
  //cal
   try
   {

       System.IO.FileInfo file = new System.IO.FileInfo(fileupload1.PostedFile.FileName);
       string fname = file.Name.Remove((file.Name.Length - file.Extension.Length), file.Extension.Length);
       fname = fname + DateTime.Now.ToString("_ddMMyyyy_HHmmss") + file.Extension;
       fileupload1.PostedFile.SaveAs(Server.MapPath("locations/") + fname);
       string filexetion = file.Extension;
       if ( filexetion == ".xlsx" )
       {
          excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Server.MapPath ( "locations/" ) + fname + ";" + ";Extended Properties=\"Excel 12.0;HDR=YES;\"";
       }
       else if ( filexetion == ".xls" )
       {
          excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath ( "locations/" ) + fname + ";" + "Extended Properties=\"Excel 8.0;HDR=Yes; \"";
       }
       OleDbConnection connection = new OleDbConnection(excelConnectionString);
       OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);
       connection.Open();
       OleDbDataReader dr = command.ExecuteReader();
       SqlConnection conn = new SqlConnection(strconnection);
       conn.Open();
       try
       {
           if (dr.Read() == true)
           {
               while (dr.Read())
               {
                   string locationname = dr["Location Name"].ToString();
                   string status = dr["Status"].ToString();
                   if (locationname != "" && status != "")
                   {
                       string query = " select locationname from tbllocations where locationname='" + locationname + "' and outletid='" + Session["outlet_id"].ToString() + "'";
                      // conn.Open();
                       SqlCommand cmdquery = new SqlCommand(query, conn);
                      SqlDataReader drreader;
                      drreader = cmdquery.ExecuteReader();
                       if (drreader.Read())
                       {

                           c = true;
                           ssss = ssss + locationname + ",";
                          // ss = ssss.Split(',');
                       }
                       else
                       {
                           drreader.Close();
                           string qryprduct = "insert into tbllocations(locationname,status,outletid,cityid)values('" + locationname + "','" + status + "','" + Session["outlet_id"].ToString() + "','" + Session["cityid"].ToString() + "')";
                           SqlCommand cmd1 = new SqlCommand(qryprduct, conn);
                           conn.Close();
                           conn.Open();
                           cmd1.ExecuteNonQuery();
                           lblerror1.Visible = true;
                           lblerror1.Text = "Locations uploaded Sucess";
                           //conn.Close();
                       }
                       drreader.Close();
                   }
               }
               // connection.Close (); conn.Close ();
           }
           else
           {
               lblerror1.Text = "There is a empty excel sheet file,plz check";
               lblerror1.Visible = true;
           }
       }
       catch (Exception ex)
       {
           lblerror1.Visible = true;
           lblerror1.Text = "Plz check the excel file formate";
       }
       finally
       {
           connection.Close(); conn.Close();
           bind();
           if (c == true)
           {
               lblerror1.Visible = true;
               lblerror1.Text = "In excel this loactions are already exist. Please check,";
               //for (int i = 0; i < ss.Length; i++)
               //{
                   lblerror3.Visible = true;
                   lblerror3.Text = ssss;
               //}
           }
       }
   }
   catch
   {
   }

}

The above code uploading is working but in excel 1st record is not uploading ,please tell me the what is the problem and give me suggestion please.

excel data is

Location Name Status
test1 1
test2 1
test3 1
test4 0
test5 1
test6 0
test7 1
test8 0
test9 1
test10 1

Thanks

Pradeep

  • 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-06-15T17:44:51+00:00Added an answer on June 15, 2026 at 5:44 pm

    You need to remove the

    if (dr.Read() == true)
    

    because it is immediately followed by a

    while (dr.Read())
    

    Each of these will read a record and the first one will skip the first row of the file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me insane! Here's the code: public static void main(String[] strings) {
This is my code: <CheckBox android:id=@+id/sprint_checkbox android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/sprint_game /> <CheckBox android:id=@+id/marathon_checkbox android:layout_width=fill_parent android:layout_height=wrap_content
i have a string like this.. /home/Abcd/Pradeep/Jack.sh /home/Abcd/Pradeep/Paul/Kill.sh I need to take Jack.sh and
This should be a simple one: I have an observableArray object called To in
This code below allows me to find the word error in all my files
This is my sample code: SPWeb web = SPContext.Current.Web SPList list = web.Lists[TestList]; try
This is starting to piss me off real bad. I have this XML code:
This is a continuation of my question Python2.5.2 The code i developed is working
This is my code: char *genWord(int wordLen){ char array[wordLen + 1]; char *word; int
this is the error... 12-17 17:17:30.729: E/SQLiteDatabase(21112): Error inserting nome=categoriaTest 12-17 17:17:30.729: E/SQLiteDatabase(21112): android.database.sqlite.SQLiteConstraintException:

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.