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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:02:34+00:00 2026-05-26T15:02:34+00:00

currently I have a web which loads excel spreadsheet data into SQL database. When

  • 0

currently I have a web which loads excel spreadsheet data into SQL database. When the page loads, all the parameters are hard coded on the code behind, so I do not have ‘browse for file’ and ‘upload’ button. I would like to implement these 2 buttons but I am not sure how should I do it.

I am using C# language, Visual Studio 2005 and SQL Server 2005.

Below is the code which runs the import of excel data into the database:

importexcel.aspx.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data.OleDb;
using System.Data.Common;
using System.Data.SqlClient;

public partial class ImportExcel : System.Web.UI.Page
{
    public static string path = @"c:\Documents and Settings\rhlim\My Documents\Visual Studio 2005\WebSites\insqlserver\studentsheet1.xls";
    public static string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=Excel 8.0;";

    protected void Page_Load(object sender, EventArgs e)
    {
        // Create Connection to Excel Workbook
        using (OleDbConnection connection =
                     new OleDbConnection(connStr))
        {
            OleDbCommand command = new OleDbCommand
                    ("Select StudentName,RollNo,Course FROM [Sheet1$]", connection);

            connection.Open();
            // Create DbDataReader to Data Worksheet
            using (DbDataReader dr = command.ExecuteReader())
            {
                // SQL Server Connection String
                string sqlConnectionString = "Data Source=<IP>;Initial Catalog=<database>;User ID=<userid>;Password=<password>";

                // Bulk Copy to SQL Server
                using (SqlBulkCopy bulkCopy =
                           new SqlBulkCopy(sqlConnectionString))
                {
                    bulkCopy.DestinationTableName = "tStudent";
                    bulkCopy.WriteToServer(dr);
                }
            }
        }
    }
}

Below is my code for the my current html:

importexcel.aspx

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="ImportExcel.aspx.cs" Inherits="ImportExcel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
<script language="javascript" type="text/javascript">
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    Please select a Excel spreadsheet to import:<br />     
        <asp:FileUpload ID="fupExcel" runat="server" /> 
        <br /> 
        <br /> 
<asp:Button ID="btnImport" runat="server"  
            Text="Import" onclick="btnImport_Click" />  
        <br />
        <br />
        <a href=http://localhost:1701/SoD>Click to go to main page</a>
        </form>

</body>
</html>

I am not sure how do I attach the 2 buttons to my background code, someone teach me? Best if with sample code, thanks a lot!

  • 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-26T15:02:35+00:00Added an answer on May 26, 2026 at 3:02 pm

    First, the code in your page load needs to execute only if(IsPostBack) or on button click.

    Second, (At leas modern) browsers won’t let you change the value of the input file field, or click it.

    You might try with some flash upload thing or so, but I don’t expect much.

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

Sidebar

Related Questions

I have a web application that loads some 50 tables from SQL Server into
I currently have a web form aspx page that calls RegisterClientScriptBlock. This sends down
All, I currently have my solution comprising of 2 Class librarys and a Web
I have an AJAX link that currently loads a partial view into a div.
Currently I have an ASP.net 4.0 app in which I've made a web reference
Some background. Currently have an asp.net web site which is contained on 2 web
I have a C# web service which currently communicates with a Flex app using
I have a currency converter application for iphone which uses web service. The web
I currently have a web site where users can select a custom theme. After
Currently I have a web application where a user can use dropdown lists to

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.