|
|
I am working on a COM dll in C# that needs to pass an ADODB recordset back to
the calling VBScript. I believe I have everthing setup correctly, as the
calls work, and it looks like a recordset is returned, however, the recordset
is null or closed. What is the trick to passing a recordset back from C#?
The Call:
Set rs = CreateObject("Interface")
rs.Init "System", "ODBC", "user", "pass", "database", "server"
retVal = rs.DataImport("value")
C#:
using ADODB;
[Guid("C3C26A94-9639-43c4-B59C-E245C8A68D44")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface iInterface
{
[DispId(1)] bool DataExport(string OrderNumber, string
TrackingNumber, decimal Freight, decimal Weight, string ShipDate, string
ShipVia, string MiscNum);
[DispId(2)] bool DataVoid(string OrderNumber, string TrackingNumber,
decimal Freight, decimal Weight, string MiscNum);
[DispId(3)] Recordset DataImport(string OrderNumber);
[DispId(4)] void Init(string nameVal, string odbcVal, string
userVal, string passVal, string dbVal, string srvVal);
}
[Guid("EF8369F0-CF42-40b1-B3F3-0EC54CE73FF4")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Interface")]
public class PSIHeader:iInterface
{
public Recordset DataImport(string OrderNumber)
{
//misc stuff - create connection, query etc...
//Recordset creation and return
rs.CursorLocation = CursorLocationEnum.adUseClient;
rs.Open(query.ToString(), cn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic, -1);
return rs;
}
}
I have been using regasm to register the type library.
Thanks
|
|
|
|
|
hi, i need to know how i can exit from sub(method) in c#, i mean keywork like exit sub in vb.net
123
|
|
|
|
|
return;
But, it is better to have only one return statement and use conditionals to control what code is executed. Refactoring often helps.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
But I am so glad at least one other person in the world shares my philosophy about return statements.
File Not Found
|
|
|
|
|
i know this keyword(return) but this keyword use in function,i need like this keyword in method
example
public void f()
{
1: command (Execute
2: Command (Execute
exit sub (in vb.net) (what i can write here like this code in c#)
3: Command (not Execute
4: Command (Not Execute
}
123
|
|
|
|
|
Suppose we have two form. FormA and FormB. FormA has a button. i want when i click the button then Form2 would be open and at that time FormA should be Dispose. but how i dispose FormA?
button click event:
Form2 oForm2=new Form2();
oForm2.ShowDialog();
this.Dispose();
but this code could not dispose the FormA.
Pls help me on this.
|
|
|
|
|
Hello,
You have to use the Show Method instead of ShowDialog.
and then Close (will call the Dispose method also) the FormA.
Form2 oForm2=new Form2();
oForm2.Show();
this.Close();
Does not work if FormA is your main form. Because then your program will end and all forms will be closed.
All the best,
Martin
|
|
|
|
|
|
Instead, you should create both forms as control, and put them both on the one form, showing one at a time.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
sorry, i can't get your point.
|
|
|
|
|
Create two user controls. Design each to look like one of the forms you need. Put both on a form. Alternate which one is Visible to decide which 'form' is showing.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Guys,
consider following code:
byte [] bytes = new byte[160];
FillBytes(ref bytes);
System.Net.IPAddress ipaddress = new System.Net.IPAddress(1684300900);
System.Net.IPEndPoint ipendpoint = new System.Net.IPEndPoint(ipaddress, 7000);
udpclient = new UdpClient();
try{
int sent = 0;
sent = udpclient.Send(bytes, bytes.Length, SystemInformation.ComputerName, 7000);
MessageBox.Show(Encoding.ASCII.GetString(bytes));
lbl_bytessent.Text = "Sent: " + sent;
}
catch(Exception ex){
MessageBox.Show("send result: error: " + ex.Message);
}
PS: I left the comments to show what I've already tried
I need to send some bytes to a receiving application. I have a small example in VB6 where it seems to work, so I tried in C# to do the same. The bytes that are sent (is set in integer sent) is always correct, the function doesn't come in the catch. However, the receiving application does not seem to react, but it does so with the VB6 application. I'm guessing I need to set some relation between sender and receiver, but I can't figure out how.
Any help on this? According to the examples on MSDN, I'm quite correct?
Thanks !
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
hi,
i am having Form1,Form2,and Form3
In Form2 i am having some values like selecting a radioButton,check box,or entering some text in the textboxes.
then i will be moving to Form3..
Now how can i Save the content of Form2..
if i come back from Form3 to Form2 i should load my values..
Help me pls
With Regards
prasad
|
|
|
|
|
First, please tell me they are not called that...
The easiest way to do this is to make your forms controls within the one form, and change which one is visible. If Form2 disappears when Form3 shows, that's the best way to approach that, in general. The other way to do it, is to just hide Form2, instead of destroying it.
The controls approach is nicer.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: ForumC#
Subject:Re: Windows Forms
Sender:Christian Graus
Date:9:35 27 Mar '07
First, please tell me they are not called that...
|
|
|
|
|
Hello,
You could hold the Form2 instance in memory (Hide), instaed of disposing (Close) every time you change to ann other form.
All the best,
Martin
|
|
|
|
|
Hello All
i am trying to read a large txt files -may 1 GB-, which coze my program to hang, and i need to know if there are techniques that make this without hang and do it faster
if you know something can help. please tell me.
|
|
|
|
|
The best thing is to avoid such files. You *can* read a file a line at a time, but I'm not sure if it loads in to memory anyhow when you do that. I'd hope not. What code are you using right now ? What is in the files ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi
You could consider using a backgroundworker to read the file, while showing a "loading" sign or something..
basically something like:
private void getTextFileWorker_DoWork(object sender, DoWorkEventArgs e)
{
//start to read the file, show loading sign...
while(morelinesinfile)
{
this.Invoke(new AddValueDelegate(AddValue), new object[] { valueFromFile });
}
}
private void AddValue(string valueFromFile)
{
//do something with the value, add it to a list...
}
private void getTextFileWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//finish up etc..hide sign..
}
best regards
HV
|
|
|
|
|
I suspect the real issue is that 1 GB of text will, on most computers, mean your RAM is full and you're using virtual memory.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
that is my code , and i had run it for a txt file its size is 423 MB, and i left my PC opened and in the mext day i found that it records about 10 hours and large number of lines about 500000 line and also i got an exception "OutOfMemoryException"
and i dont know much about "backgroundworker", if you know a complete example plz provid me by the link
StreamReader SR;
private void btnReadFile_Click(object sender, EventArgs e)
{
DateTime DT= DateTime.Now;
TimeSpan T = new TimeSpan(DT.Day, DT.Hour, DT.Minute, DT.Second);
if (SR != null)
{
while (!SR.EndOfStream)
{
try
{
string line = SR.ReadLine();
txtFileContent.AppendText(line);
txtFileContent.AppendText("\n");
txtFileContent.AppendText("\r");
int count = Convert.ToInt32(labNumOfLines.Text);
count++;
labNumOfLines.Text = count.ToString();
DateTime tempTime = DateTime.Now;
TimeSpan T2 = new TimeSpan(tempTime.Day, tempTime.Hour, tempTime.Minute, tempTime.Second);
T2=T2.Subtract(T);
labTime.Text = T2.ToString();
this.Refresh();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
|
|
|
|
|
Is txtFileContent a string or a StringBuilder ? IF the former replacing it with the latter will see a massive performance boost. A string is immutable, which means each time you do txtFileContent.AppendText(line); you're creating a new string and copying the old one to it. For normal use immutable strings allow certain optimizations that result in faster code, but when building a really large string they absolutely murder performance. IF you;re using a string for each line of your file you're copying everything read so far three times. And absolutely thrashing the GC in the process.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
txtFileContent is a textBox
|
|
|
|
|
That almost certainly uses a string internally. Load the entire thing into a stringbuilder first and then copy when complete. Even then I seriously doubt the tb is capable of handling that large a string in a managable fashion.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|