Click here to Skip to main content
15,900,258 members
Home / Discussions / C#
   

C#

 
QuestionManaged C# DLL called from native C main with callbacks Pin
Stuart Rubin12-Jul-11 4:18
Stuart Rubin12-Jul-11 4:18 
AnswerRe: Managed C# DLL called from native C main with callbacks Pin
Pete O'Hanlon12-Jul-11 5:57
mvePete O'Hanlon12-Jul-11 5:57 
GeneralRe: Managed C# DLL called from native C main with callbacks Pin
GuyThiebaut12-Jul-11 10:28
professionalGuyThiebaut12-Jul-11 10:28 
GeneralRe: Managed C# DLL called from native C main with callbacks Pin
Stuart Rubin13-Jul-11 7:04
Stuart Rubin13-Jul-11 7:04 
GeneralRe: Managed C# DLL called from native C main with callbacks Pin
Pete O'Hanlon13-Jul-11 7:09
mvePete O'Hanlon13-Jul-11 7:09 
GeneralRe: Managed C# DLL called from native C main with callbacks Pin
Stuart Rubin13-Jul-11 7:24
Stuart Rubin13-Jul-11 7:24 
GeneralRe: Managed C# DLL called from native C main with callbacks Pin
Pete O'Hanlon13-Jul-11 7:38
mvePete O'Hanlon13-Jul-11 7:38 
Questionimporting some data form excell to database Pin
cpokazi12-Jul-11 2:33
cpokazi12-Jul-11 2:33 
Hi all I have a problem i am importing data from an excell spreadsheet to a sql 2008 database ,and i can do that in c# 3.5 getting all fields in the spreadsheet the same as the ones in the db..

I want to select now a few fields and insert them or rather import them to the database not all fields are the same here heres my code and i am getting this error
" The connection was not closed. The connection's current state is open."

i want only these 2 fields(DOC_TPL_CGY_TP_DESC ,USR ) from excell now to dbs the other two i will insert namually please help

private void btnDocumentCat_Click(object sender, EventArgs e)
{
string oconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\2010Projects\\Project1\\DocumentCatalogue\\bin\\Debug\\MyExcelFile.xls;Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\";";
OleDbConnection con = new OleDbConnection(oconn);

string filepath = @"C:\\2010Projects\\Project1\\DocumentCatalogue\\bin\\Debug\\MyExcelFile.xls";
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filepath + ";" + "Extended Properties=Excel 8.0;";


using (OleDbConnection cn = new OleDbConnection(ConnectionString))
{
cn.Open();
DataTable dbSchema = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dbSchema == null || dbSchema.Rows.Count < 1)
{
throw new Exception("Error: Could not determine the name of the first worksheet.");
}
string WorkSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString();


OleDbCommand ocmd = new OleDbCommand("SELECT * FROM [" + WorkSheetName + "]", cn);

OleDbCommand OCM = new OleDbCommand("SELECT DOCUMENT NAME ,USER FROM [" + WorkSheetName + "]", con);
DataTable dt = new DataTable(WorkSheetName);

OleDbDataReader odr = OCM.ExecuteReader();

//OleDbDataReader URD = OCM.ExecuteReader();


string DOC_TPL_CGY_TP_DESC = string.Empty;
string DOC_TPL_CGY_TP_CODE = string.Empty;
int DOC_TPL_CGY_TP_ID = 0;
string USR = string.Empty;

while (odr.Read())
{
// DOC_TPL_CGY_TP_CODE = valid(odr, 0);
DOC_TPL_CGY_TP_DESC = valid(odr, 0);
USR = valid(odr, 1);

Insertdataintosql2(DOC_TPL_CGY_TP_CODE,DOC_TPL_CGY_TP_DESC,DOC_TPL_CGY_TP_ID, USR);
}



}
}

private void Insertdataintosql2(string DOC_TPL_CGY_TP_CODE, string DOC_TPL_CGY_TP_DESC, int DOC_TPL_CGY_TP_ID, string USR)
{
throw new NotImplementedException();
}
sipho

AnswerRe: importing some data form excell to database Pin
PIEBALDconsult12-Jul-11 3:16
mvePIEBALDconsult12-Jul-11 3:16 
GeneralRe: importing some data form excell to database Pin
cpokazi12-Jul-11 3:27
cpokazi12-Jul-11 3:27 
GeneralRe: importing some data form excell to database Pin
PIEBALDconsult12-Jul-11 15:09
mvePIEBALDconsult12-Jul-11 15:09 
AnswerRe: importing some data form excell to database Pin
Shameel12-Jul-11 3:48
professionalShameel12-Jul-11 3:48 
GeneralRe: importing some data form excell to database Pin
cpokazi12-Jul-11 4:04
cpokazi12-Jul-11 4:04 
GeneralRe: importing some data form excell to database Pin
Shameel12-Jul-11 4:37
professionalShameel12-Jul-11 4:37 
GeneralRe: importing some data form excell to database Pin
cpokazi12-Jul-11 4:44
cpokazi12-Jul-11 4:44 
GeneralRe: importing some data form excell to database Pin
Shameel12-Jul-11 23:43
professionalShameel12-Jul-11 23:43 
QuestionSendKeys.Send("^v") Pin
gumigyuri11-Jul-11 22:58
gumigyuri11-Jul-11 22:58 
AnswerRe: SendKeys.Send("^v") Pin
DaveAuld11-Jul-11 23:12
professionalDaveAuld11-Jul-11 23:12 
GeneralRe: SendKeys.Send("^v") Pin
gumigyuri11-Jul-11 23:19
gumigyuri11-Jul-11 23:19 
GeneralRe: SendKeys.Send("^v") Pin
DaveAuld11-Jul-11 23:40
professionalDaveAuld11-Jul-11 23:40 
GeneralRe: SendKeys.Send("^v") Pin
Dave Kreskowiak12-Jul-11 1:38
mveDave Kreskowiak12-Jul-11 1:38 
GeneralRe: SendKeys.Send("^v") Pin
MicroVirus12-Jul-11 7:13
MicroVirus12-Jul-11 7:13 
AnswerRe: SendKeys.Send("^v") Pin
Abhinav S12-Jul-11 0:28
Abhinav S12-Jul-11 0:28 
AnswerRe: SendKeys.Send("^v") Pin
Bernhard Hiller19-Jul-11 0:32
Bernhard Hiller19-Jul-11 0:32 
QuestionClass Hierarchy To XML Pin
Kevin Marois11-Jul-11 11:36
professionalKevin Marois11-Jul-11 11:36 

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.