Solved

Converting Delphi (pascal) to C#

Posted on 2006-07-09
10
801 Views
Last Modified: 2010-05-18
Hi guys

im making a program for restore a MS SQL database remotly. I am trying to catch the infomessage the sql server send but i dont make it. I made same thing in delphi long time ago and have fogotten how i was thinking that time. anyway i still have the code for it in delphi but im vey new in C# and would like someone to translate this delphi code to C# (VS 2005). Thanks guys.

procedure TForm1.ADOConnection1InfoMessage(Connection: TADOConnection;
  const Error: Error; var EventStatus: TEventStatus);


begin



  if error.Description = '10 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '20 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '30 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '40 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '50 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '60 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '70 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '80 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '90 percent backed up.' then Form1.Progressbar1.StepIt;
  if error.Description = '100 percent backed up.' then Form1.Progressbar1.StepIt;
end;

I would like to know how to catch them to a memobox also.
0
Comment
Question by:AgdaLon
  • 6
  • 4
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17068923
Add a handler to the InfoMessage event:

   SqlConnection conn = new SqlConnection();
   conn.InfoMessage += new SqlInfoMessageEventHandler(InfoMessageSink);

   private void InfoMessageSink(object source, SqlInfoMessageEventArgs e)
  {
  }

Bob
0
 

Author Comment

by:AgdaLon
ID: 17068942
thanks bob... how do i catch it in the procedure?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17068959
I am not sure I understand your question?  Stored procedure?  C# procedure?

Are you asking where to put that code?

Bob
0
 

Author Comment

by:AgdaLon
ID: 17068973
I would like to know to catch the info whitch comes bck from SQL server to

private void InfoMessageSink(object source, SqlInfoMessageEventArgs e)
  {

How do i write here

if "error" = then ...

or

memobox.item.add(error);

I have not a clue how to write here....
  }



Thanks for your patiens...

Johan
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17068989
Johan,

Try this:

private void InfoMessageSink(object source, SqlInfoMessageEventArgs e)
{
   memobox.Items.Add(e.Message);
}

Bob
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:AgdaLon
ID: 17069018
it works almost ... but i only get 2 percent restored3percent restored6percentrestored
then no more ;(
 i dont find memobox so i used listbox...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17069025
I guess you mean that a Memo box is a multi-line TextBox control, right?

>>then no more
Are you getting an exception?  Is it completing, just not giving you the right progress?

Bob
0
 

Author Comment

by:AgdaLon
ID: 17069064
it send all progress in one string,.... if i debugg it it comes like this (in one string)

2 percent restored.
4 percent restored.
6 percent restored.
8 percent restored.
10 percent restored.
12 percent restored.
14 percent restored.
16 percent restored.
18 percent restored.
20 percent restored.
22 percent restored.
24 percent restored.
27 percent restored.
29 percent restored.
31 percent restored.
33 percent restored.
35 percent restored.
37 percent restored.
39 percent restored.
41 percent restored.
43 percent restored.
45 percent restored.
47 percent restored.
49 percent restored.
52 percent restored.
54 percent restored.
56 percent restored.
58 percent restored.
60 percent restored.
62 percent restored.
64 percent restored.
66 percent restored.
68 percent restored.
70 percent restored.
72 percent restored.
74 percent restored.
77 percent restored.
79 percent restored.
81 percent restored.
83 percent restored.
85 percent restored.
87 percent restored.
89 percent restored.
91 percent restored.
93 percent restored.
95 percent restored.
97 percent restored.
99 percent restored.
100 percent restored.
Processed 384 pages for database 'Northwind', file 'Northwind' on file 1.
Processed 1 pages for database 'Northwind', file 'Northwind_log' on file 1.
RESTORE DATABASE successfully processed 385

I trried this but it doesnt work ...
if (e.Message=="10 percent restored.")
          listBox1.Items.Add("10 percent restored.");
     if (e.Message=="100 percent restored.")
          listBox1.Items.Add("100 percent restored.");
0
 

Author Comment

by:AgdaLon
ID: 17069257
I found it in MSDN it should look like this to work.... it just need a bit polish now...

thanks for your help mate..

J
0
 

Author Comment

by:AgdaLon
ID: 17069270
forgot the code...

 

private void InfoMessageSink(object source, SqlInfoMessageEventArgs e)
  {
     // listBox1.Items.Add(e.Errors.Count);
             for (int i = 0; i < e.Errors.Count; i++)
    {       listBox1.Items.Add(e.Errors[i].Message);
             }
thanks for your help mate..

J
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now