Click here to Skip to main content
15,889,651 members
Home / Discussions / COM
   

COM

 
QuestionHow to regsvr32 ***.ocx successful? Pin
huangdingjun25-Oct-08 16:29
huangdingjun25-Oct-08 16:29 
AnswerRe: How to regsvr32 ***.ocx successful? Pin
Wes Aday25-Oct-08 19:00
professionalWes Aday25-Oct-08 19:00 
GeneralRe: How to regsvr32 ***.ocx successful? Pin
huangdingjun27-Oct-08 1:26
huangdingjun27-Oct-08 1:26 
GeneralRe: How to regsvr32 ***.ocx successful? Pin
Rajasekharan Vengalil4-Nov-08 9:29
Rajasekharan Vengalil4-Nov-08 9:29 
QuestionVB 6, ASP and COM Pin
indian14322-Oct-08 23:31
indian14322-Oct-08 23:31 
QuestionSystem.OutOfMemoryException: Retrieving the COM class factory for component with CLSID {29131539-2EED-1069-BF5D-00DD011186B7} failed due to the following error: 8007000e. Pin
blakshmi21-Oct-08 22:44
blakshmi21-Oct-08 22:44 
AnswerRe: System.OutOfMemoryException: Retrieving the COM class factory for component with CLSID {29131539-2EED-1069-BF5D-00DD011186B7} failed due to the following error: 8007000e. Pin
User 21559724-Oct-08 0:16
User 21559724-Oct-08 0:16 
QuestionAutoformat an Excel file and import it into Sql Sever 2000 Pin
Nitin Raj21-Oct-08 22:03
Nitin Raj21-Oct-08 22:03 
hi,

I am trying to autoformat an Excel (.xls) file and then import it into Sql server 2000 table using C# in Asp.net. But when i try to autoformat the excel file i get the exception "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Someone please help me to solve this problem

Here is the code.

sing System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

using System.Data.OleDb;

using System.Data.Odbc;

using System.Text;

using Microsoft.Office.Interop.Excel;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

SqlConnection Cn = new SqlConnection("server=143.14.45.137; database= NitDB; User ID=uy; Password= g");

SqlCommand Cm = new SqlCommand("Select * from ExcelFile", Cn);

Cn.Open();

SqlDataReader St = Cm.ExecuteReader();

gdExcelFile.DataSource = St;

gdExcelFile.DataBind();

St.Close();

Cn.Close();

}

public static void PrintProgressBar()

{

StringBuilder sb = new StringBuilder();

sb.Append("<div id='updiv' style='Font-weight:bold;font-size:11pt;Left:320px;COLOR:black;font-family:verdana;Position:absolute;Top:140px;Text-Align:center;'>");

sb.Append("&nbsp;<script> var up_div=document.getElementById('updiv');up_div.innerText='';</script>");

sb.Append("<script language=javascript>");

sb.Append("var dts=0; var dtmax=10;");

sb.Append("function ShowWait(){var output;output='Reading data from excel...PLEASE WAIT!';dts++;if(dts>=dtmax)dts=1;");

sb.Append("for(var x=0;x < dts; x++){output+='';}up_div.innerText=output;up_div.style.color='red';}");

sb.Append("function StartShowWait(){up_div.style.visibility='visible';ShowWait();window.setInterval('ShowWait()',100);}");

sb.Append("StartShowWait();</script>");

HttpContext.Current.Response.Write(sb.ToString());

HttpContext.Current.Response.Flush();

}

public static void ClearProgressBar()

{

StringBuilder sbc = new StringBuilder();

sbc.Append("<script language='javascript'>");

sbc.Append("alert('Data exported successfully');");

sbc.Append("up_div.style.visibility='hidden';");

sbc.Append("history.go(-1)");

sbc.Append("</script>");

HttpContext.Current.Response.Write(sbc);

}

protected void btnExport_Click(object sender, EventArgs e)

{



PrintProgressBar();

{

OdbcConnection connection;

SqlBulkCopy bulkCopy;

string ConnectionString = @"server=178.17.44.137;database= NitDB; User ID= er; Password=d";

string connstr = @"Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" + fyle.Value;

using (connection = new OdbcConnection(connstr))

{

string[] temp;

string fn1;

fn1 = System.IO.Path.GetFileName(fyle.PostedFile.FileName); \\ fyle is the Html File upload control

temp = fn1.Split('.');

object missing = System.Reflection.Missing.Value;

Microsoft.Office.Interop.Excel.Application excel = default(Microsoft.Office.Interop.Excel.Application);

Microsoft.Office.Interop.Excel.Workbook wb = default(Microsoft.Office.Interop.Excel.Workbook);

excel = new Microsoft.Office.Interop.Excel.Application();

// I get the exception at the below statement.

wb = excel.Workbooks.Open(fn1, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

excel.Visible = true;

//wb.Activate();

excel.Cells.Select();

excel.Columns.AutoFit();

excel.Rows.AutoFit();



OdbcCommand command = new OdbcCommand("Select * FROM [" + temp[0].ToString() + "$]", connection);

connection.Open();

using (OdbcDataReader dr = command.ExecuteReader())

{

using (bulkCopy = new SqlBulkCopy(ConnectionString))

{

bulkCopy.DestinationTableName = "ImportedExcel";

bulkCopy.WriteToServer(dr);

}

dr.Close();

}

}

bulkCopy.Close();

connection.Close();

}

ClearProgressBar();

}


}

Nitin Raj Bidkikar

QuestionMAPI hooks Pin
Dr. Kelwin21-Oct-08 14:55
Dr. Kelwin21-Oct-08 14:55 
QuestionCrashes on application exit while hosting an VB ActiveX Control providing UI in a MFC application Pin
Martin081521-Oct-08 2:07
professionalMartin081521-Oct-08 2:07 
AnswerRe: Crashes on application exit while hosting an VB ActiveX Control providing UI in a MFC application Pin
Ernest Laurentin21-Oct-08 7:55
Ernest Laurentin21-Oct-08 7:55 
GeneralRe: Crashes on application exit while hosting an VB ActiveX Control providing UI in a MFC application Pin
Martin081522-Oct-08 0:59
professionalMartin081522-Oct-08 0:59 
AnswerRe: Crashes on application exit while hosting an VB ActiveX Control providing UI in a MFC application Pin
Martin081522-Oct-08 4:46
professionalMartin081522-Oct-08 4:46 
GeneralSolved - Re: Crashes on application exit while hosting an VB ActiveX Control providing UI in a MFC application Pin
Martin081528-Oct-08 23:07
professionalMartin081528-Oct-08 23:07 
QuestionRelease COM interfaces Pin
john563220-Oct-08 20:41
john563220-Oct-08 20:41 
AnswerRe: Release COM interfaces Pin
Roger Stoltz20-Oct-08 21:18
Roger Stoltz20-Oct-08 21:18 
AnswerRe: Release COM interfaces [modified] Pin
john563220-Oct-08 22:34
john563220-Oct-08 22:34 
GeneralRe: Release COM interfaces Pin
Roger Stoltz21-Oct-08 3:58
Roger Stoltz21-Oct-08 3:58 
AnswerRe: Release COM interfaces Pin
Member 459552813-Nov-08 20:30
Member 459552813-Nov-08 20:30 
Questionwhat is .pfx file Pin
wasimsharp19-Oct-08 23:47
wasimsharp19-Oct-08 23:47 
QuestionUsing MsComm for recieving data Pin
tauras8118-Oct-08 0:08
tauras8118-Oct-08 0:08 
JokeRe: Using MsComm for recieving data Pin
CPallini18-Oct-08 1:36
mveCPallini18-Oct-08 1:36 
AnswerRe: Using MsComm for recieving data Pin
Mike Dimmick19-Oct-08 0:38
Mike Dimmick19-Oct-08 0:38 
Question[Message Deleted] Pin
_nnemo_16-Oct-08 3:18
_nnemo_16-Oct-08 3:18 
AnswerRe: IWebBrowser2 - object deletion Pin
Mike Dimmick19-Oct-08 0:40
Mike Dimmick19-Oct-08 0:40 

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.