Click here to Skip to main content
15,897,187 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Editable gridview in ASP.NET MVC 2.0 Pin
M. K. BASHER24-May-10 23:47
M. K. BASHER24-May-10 23:47 
Questionselecting data from excel sheet Pin
swtlibra24-May-10 19:10
swtlibra24-May-10 19:10 
AnswerRe: selecting data from excel sheet Pin
Gaurav Dudeja India24-May-10 19:12
Gaurav Dudeja India24-May-10 19:12 
GeneralRe: selecting data from excel sheet Pin
swtlibra24-May-10 19:46
swtlibra24-May-10 19:46 
GeneralRe: selecting data from excel sheet Pin
Gaurav Dudeja India24-May-10 20:48
Gaurav Dudeja India24-May-10 20:48 
QuestionDataList HeaderTemplate Problem Pin
jitendrafaye24-May-10 18:59
jitendrafaye24-May-10 18:59 
Questioncalender Pin
luckydear24-May-10 18:42
luckydear24-May-10 18:42 
QuestionLoad Excel file into Database using FileUpload Control Error Pin
cheguri24-May-10 18:35
cheguri24-May-10 18:35 
Dear friends, I am uploading Excel sheet data using FileUpload control and want to store the data into sql server 2005 database. Excel Sheet file name is same as Table name in Database and Column headings are same as columns in database table. In my machine, I don't have MS Office. I am using OpenOffice now. I am getting an error "The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly." . I have written the following complete code. Please help me. Its very urgent. Please please please. The code is

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
{
SqlConnection connection=new SqlConnection("data source=10.0.3.30;initial catalog=rambasedev;user id=sa;password=admin");
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
{
Boolean fileOK = false;
String path = Server.MapPath("~/UploadedFiles/");
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".xls", ".xlsx" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{

string xConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath(FileUpload1.FileName) + ";" + "Extended Properties=Excel 8.0;";
using (OleDbConnection connection = new OleDbConnection(xConnStr))
{
OleDbCommand command = new OleDbCommand("Select EMPNO,ENAME,BASIC FROM [Sheet1$]", connection);

connection.Open();

// Create DbDataReader to Data Worksheet
using (OleDbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "Data Source=10.0.3.30;Initial Catalog=RambaseDev;Integrated Security=True";

// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "SamplePS";
bulkCopy.WriteToServer(dr);
}
}
}
}
catch (Exception ex)
{
Success.Text = "File could not be uploaded.";
}
}
else
{
Success.Text = "Cannot accept files of this type.";
}
}

}
}




Please help me.

Regards,
Dileep
AnswerRe: Load Excel file into Database using FileUpload Control Error Pin
Tej Aj24-May-10 20:23
Tej Aj24-May-10 20:23 
GeneralRe: Load Excel file into Database using FileUpload Control Error Pin
cheguri25-May-10 0:14
cheguri25-May-10 0:14 
GeneralRe: Load Excel file into Database using FileUpload Control Error Pin
Tej Aj25-May-10 3:29
Tej Aj25-May-10 3:29 
QuestionHow can Access a Div without add runar="server" in code behind? Pin
anoop_m8324-May-10 12:58
anoop_m8324-May-10 12:58 
AnswerRe: How can Access a Div without add runar="server" in code behind? Pin
Not Active24-May-10 13:35
mentorNot Active24-May-10 13:35 
GeneralRe: How can Access a Div without add runar="server" in code behind? Pin
anoop_m8324-May-10 13:46
anoop_m8324-May-10 13:46 
GeneralRe: How can Access a Div without add runar="server" in code behind? Pin
Not Active24-May-10 14:17
mentorNot Active24-May-10 14:17 
GeneralRe: How can Access a Div without add runar="server" in code behind? Pin
anoop_m8324-May-10 14:33
anoop_m8324-May-10 14:33 
AnswerRe: How can Access a Div without add runar="server" in code behind? Pin
doudoufly2-Jun-10 0:05
doudoufly2-Jun-10 0:05 
QuestionExample ASP.NET training project, which uses a database, users can enter under the login and apply the session. Pin
vn2145624-May-10 10:50
vn2145624-May-10 10:50 
QuestionDynamic Content + Reflection + Server Controls Pin
CP_Klewis24-May-10 10:25
CP_Klewis24-May-10 10:25 
AnswerRe: Dynamic Content + Reflection + Server Controls Pin
T M Gray24-May-10 11:05
T M Gray24-May-10 11:05 
GeneralRe: Dynamic Content + Reflection + Server Controls Pin
CP_Klewis25-May-10 1:27
CP_Klewis25-May-10 1:27 
QuestionWeb Service on https site Pin
#realJSOP24-May-10 9:48
professional#realJSOP24-May-10 9:48 
QuestionGridview containing dependent dropdownlists errors on edit. Pin
janetb9924-May-10 9:09
janetb9924-May-10 9:09 
QuestionHow to get the date value from Date time Pin
Amit Patel198524-May-10 9:00
Amit Patel198524-May-10 9:00 
AnswerRe: How to get the date value from Date time Pin
Not Active24-May-10 9:09
mentorNot Active24-May-10 9:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.