|
Stuart, you need to expose your event as described in this[^] example. This creates the COM hookup for the event handler that you can reference through your C code.
|
|
|
|
|
Nice one - I think that is going to come in handy to me some day too.
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Peter, this is helpful, but at least half of the challenge is on the native (un-managed) side. I think now I have a syntactic problem with registering my native C function with the managed event.
Any more tips?
Thanks!
|
|
|
|
|
That side is going to require you to hook up to the COM event in your C code. You might want to read this[^] article to see how C++ handles it (it should be easy enough to apply this to C).
|
|
|
|
|
"Calling" the managed functions isn't really a problem anymore. The real problem is passing in a reference to the unamanged event handler function into the managed event. Sorry to keep pushing on this, but does sound like you know what you're doing!
Thanks again.
|
|
|
|
|
Have you assigned the IConnectionPoint interface[^]? As you've implemented the event interface in your C#, the CLR Interop automatically applies the juice that hooks this together.
|
|
|
|
|
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
|
|
|
|
|
That code sure is hard to read without PRE tags.
Which line is giving the Exception?
Why use @ and \\ ?
What are the DataTable dt and OleDbCommand ocmd used for?
Is the connection to the destination database open?
|
|
|
|
|
oh yes i saw my connection was wrong...thanks but yes am still struggling i wanna select a few colomns from the excel sheet to the dbs but i aint sure how to do that if its not all columns.
|
|
|
|
|
I just don't see what would give you that error.
|
|
|
|
|
Why take all the pains to do it in C#, when you can do it in TSQL directly.
select * from OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\myexcel.xls', 'select * from [Sheet1$]')
|
|
|
|
|
OleDbCommand OCM = new OleDbCommand("SELECT DOCUMENT_NAME ,USER FROM [" + WorkSheetName + "]", cn);
i am using the above way because i only want thse two coloumns form my excel and import them to a dbs table but i still am getting an arror..please help
error "No value given for one or more required parameters."
|
|
|
|
|
Did you name the columns in the spreadsheet? By default, the values in the first row are treated as column names.
|
|
|
|
|
yes my spreadsheet coloumns are the ones in this line of code
OleDbCommand OCM = new OleDbCommand("SELECT [DOCUMENT_NAME] ,[USER] FROM [" + WorkSheetName + "]", cn);
OleDbDataReader odr = OCM.ExecuteReader();
when i build my app it can not go tru this statement gives me this error
"No value given for one or more required parameters." because what i am trying to do is get documentname and user name from excell then store it in a table but now i can get these ..
Hope i did answer you question
|
|
|
|
|
Ensure that the WorkSheetName variable ends with a dollar ($) symbol.
|
|
|
|
|
Hi all
I'm having trouble with my app and i need some help.
I have an app that needs to paste some numbers from a listbox into another App.
Using
SendKeys.Send("^v");
works great while working on a local computer, the problem is that i'm working on a remote desktop and sometimes when sending the "^v" it only sends the "v"
Can anyone help me figure this out ?
Thanks in advance.
|
|
|
|
|
|
I don't think that's the problem , because it works without the {} , but for example when i have 50 numbers in the listbox, pasting 45-47 number is OK, while it makes 3-5 random mistakes, sending only the "v".
To emulate "Control" you don't need {} because than it will send the "^" character only...
|
|
|
|
|
|
Those a control characters to SendKeys. If you want to send those actual characters, you have to enclose them in the curly braces.
He's sending Control-V, which is correct in his code.
The technique, on the other hand, of using SendKeys at all is suspect.
|
|
|
|
|
I agree. Basically, using SendKeys is per definition unreliable. Best to code what you want (and keep control), rather than relying on a quirky method that can go wrong at any turn.
|
|
|
|
|
Try running remote desktop in full screen mode.
Apparentely, Remote Desktop only acknowledges key strokes in full screen mode.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Try sending an additional printable character afterwards, e.g. a space: "^v ". Some time ago, I experienced a situation where that helped, but I do not know why that worked...
|
|
|
|
|
What's involved in converting a hierarchy of classes to an XML file? I'm not talking about serialization. I just want to take a collection of objects and create an XML file out of it?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: I just want to take a collection of objects and create an XML file out of it?
Actually, that is serialisation, to XML at least. The path of least resistance is to use the built in XML serialisation.
If you don't want to do this you nned to use reflection to traverse the object graph whilst writing the XML to file.This is slightly harder than it sounds,as you also need to take into account collections and potential loops in the graph.
Personally, I'd go for the built-in option if possible. You can write your own formatter if the built in one isn't to requirements.
|
|
|
|