|
What type of connection is this? Database? File share? Custom protocol?
Start by putting all of your communication-related code into a separate class (or at least identifying which classes you use fits this description): should specific exceptions get thrown, you simply reinstantiate or reconfigure the class with different parameters (telling it to use server B). In the case of a database connection, as an example, you would change the connection string.
This outlines the structure of a solution, but without more information I can't really help you.
|
|
|
|
|
Hi,
Tks for the reply. The connection is a database one. I had guess changing the connection string. However does connection lost or no connection exceptions come with common error strings.
I guessing using this.
try
{
str1 = db1;
conn.ConnectionString = str1'
conn.open();
}
catch(Exception msg)
{
if(msg.Message.ToString()=="No Connection")
{
try
{str1 = db2;
conn.ConnectionString = str1;
conn.Open();
}
catch(Exception msg1)
{
MessageBox.Show("Total Connection Lost");
}
}
}
Something like these?
|
|
|
|
|
Try: catch (SqlException ex). You can get far more from exceptions than that:
Put a breakpoint on your MessageBox.Show, then quick-view the exception when the code gets there. You'll get a lot of info from there, including the actual sub-type of the exception that got thrown.
|
|
|
|
|
tks for the reply...
ok i tried that...I'm guessing i could use the number property to specify the error that i need to process..Also, there's one thing that puzzle me. There is a ConnectionState.Broken...when will this state occur? i tried have a connection open..then pluck off the cable..so i thought this is suppose to be connection broken. However the state of the connection is still open. Is there anything that i can refer to as to detect a break in connection from an open connect?
|
|
|
|
|
hi..
i hav developed an application to send fax automatically..i want to put this application in to the system tray how can i do that..
thanks...
|
|
|
|
|
for that u can use notifyIcon
|
|
|
|
|
|
Hi,
Suppose I have:
class Point
{
private int x,y;
public void Point()
{
........
}
public int X
{
set{x=value;}
get{return x;}
}
public int Y
{
set{y=value;}
get{return y;}
}
public void Draw()
{
....
Console.WriteLine("*");
}
}
class MainApp
{
static void Main()
{
Point p=new Point();
p.X=10;
p.Y=10;
p.Draw();
}
}
I want that When i call p.Draw() ,will appear '*' at position (p.X,p.Y).
Please ,help me.
Thanks a lot!
|
|
|
|
|
hi there,
do u mean that it'll draw * character in console or window form mode?
if window form mode, u cannot use Console.writeln...
if console mode, u hv to jump the cursor to that position and simpy write start character to the console.
<< >>
|
|
|
|
|
Hi Friends,
How to use OLE object to retrieve data into Multilayerd Spread Sheet. I am able to retrieve data into multi-tab spread sheet. I could not able to pull the data into multi-layered spread sheet.How to create Multi-Layered spread sheet using C#?
Sarat Gollapudi
|
|
|
|
|
Dear friends,
I have to write a project that's able to read & write data to an excel file. Just simply like a data base program.
do you have any hints or example?
|
|
|
|
|
I had a big headache trying to do this myself. There may be a way to read and write to a file, but I found I a diffent way to write to Excel, and a different was of reading from, with some help from one of our friends on the CodeProject.
Here is a simple example of writing to Excel. It creates a new Excel book and writes a string in the 1st cell.
/**************************************************/
using System;
using Excel;
using System.IO;
using System.Text;
using System.Data.OleDb;
namespace Writing_to_Excel_example
{
class Class1
{
static void Main(string[] args)
{
bool xlsError = false;
int rowCount = 0;
int counter = 0;
int counter2 = 0;
Console.WriteLine("Working...");
Excel.Application ExcelObj = new Excel.Application();
Excel.Workbook workbook = ExcelObj.Workbooks.Add(Type.Missing);
if (ExcelObj == null)
{
Console.WriteLine("\nERROR: EXCEL couldn't be started!");
xlsError = true;
}
// activate the active worksheet in the workbook
Worksheet ws = (Worksheet)ExcelObj.ActiveSheet;
ws.Activate();
try
{
//To enter text to a specific row and column:
((Range)ws.Cells[1, 1]).Value2 = ("This is Row 1, Column 1");
//To set an entire row as Bold.
((Range)ws.Cells[rowCount, 1]).EntireRow.Font.Bold = true;
}//end try
catch(Exception e)
{
Console.Write(e);
}
//Make Excel visible.
ExcelObj.Visible = true;
}
}
}
/***************************************************************/
DONT FORGET TO ADD REFERENCE TO EXCEL 11.0 OBJECT LIBRARY!!
As for reading from excel, I tried to apply the same sort of logic as above but it didn't work. So have a look at this link:
http://www.codeproject.com/csharp/FasterExcelAccessTOC.asp[^]
Great tips there, a great help to me, Thanks to Dusty Candland, great help mate!!
t-seanm
|
|
|
|
|
Hi!
I need to build/utilize a special printer driver.
Say my printer name is XYZ.
If from any Win Application, I print some document on XYZ, the file must be 'copied' to some specified folder.
This is like a File Copy Agent Printer Driver.
Any info whether there is something like this.
Thanks in advance.
malikware
|
|
|
|
|
Depends on the format you want it to be 'copied' as. There are many PDF print drivers that you can programmatically set (usually through the registry) to dump the printed output to a folder as a PDF file. Check out www.PDFmachine.com for one such example.
|
|
|
|
|
I've searched all over, but I cant for the life of me find anywhere that someone has made (or knows how to make) a button with a drop-down arrow, like the button when you use "Add Existing Item" to a project, the Add button has a dropdown.
Infragistics have a UltraDropDownButton that does this, but it doesn't look like a windows button and I can't get it to.
Any tips?
--
Dave
|
|
|
|
|
Run character map and have a look at the Wingdings and Symbol fonts (I think the drop-down arrow that you're looking for is in Webdings 3). Enter the corresponding character in the button's text field, and set the appropriate font. You'd probably want give the button an "action" part for executing the default, and a "drop-down" part that shows your pop-up menu; so do this as two separate buttons. Putting these on a panel would also be a good idea. For the actual pop-up bit, set up a context menu to pop up when the user clicks on the drop-down button.
|
|
|
|
|
Here is an example from a button control that I created. The drop-down arrow is represented by the number 6 in the Marlett font.
<br />
System.Drawing.Graphics g = this.CreateGraphics();<br />
System.Drawing.Font font = new System.Drawing.Font("Marlett", this.Font.Size);<br />
System.Drawing.SizeF sizeF = g.MeasureString("6", font);<br />
<br />
Brush brush = Enabled ? SystemBrushes.ControlText : new SolidBrush(SystemColors.GrayText);<br />
<br />
g.DrawString("6", font, brush, <br />
Width - 4 - sizeF.Width, (Height - sizeF.Height) / 2.0f);<br />
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
From a string like this: "A B C" or "D A C B" (number and order of letters doesn't matter). How can I generate all possible subsets recursively? I've tried everything and I can do it with iteration mode but can't find a pattern to use with recursion!
To:
"A B C":
Generate:
A
B
C
A B
A C
B C
A B C
|
|
|
|
|
This method should do the job:
private void SearchCombinations(string[] splitted, int currentIndex, string resultSoFar, ArrayList results)
{
if (currentIndex >= splitted.Length)
return;
string nextResult = resultSoFar + splitted[currentIndex];
results.Add(nextResult);
SearchCombinations(splitted, currentIndex + 1, nextResult, results);
SearchCombinations(splitted, currentIndex + 1, resultSoFar, results);
}
where the initial call should be something like:
ArrayList results = new ArrayList();
SearchCombinations("A B C D".Split(' '), 0, "", results);
and to make output at the end:
string output = "Combination Count:" + results.Count;
foreach (string s in results)
output += "\n" + s;
Note that this is very memory hungry because all results are stored in memory, but for 26 characters (I tried it with the whole alphabet) it should work (although taking some time because of paging).
|
|
|
|
|
i've added to my application a setup solution.
I've got all the standard form that visual studio made automatically.
If i want handle the main function of the form n°1 or handle the click of the button... how can i do?
|
|
|
|
|
I am creating an ASP.Net web application using C# and want to know how do I display a script message when I enter a page or leave the same page. I have this code in the Page_Load
string alertScript = "<script language=JavaScript>";
alertScript += "alert('" + "Message" +"');";
alertScript += "</script" +">";
if (!IsClientScriptBlockRegistered("alert"))
this.RegisterClientScriptBlock("alert", alertScript);
When I enter the page, the message is displayed, but when I leave the page the message is not displayed. How do I get the message to display when I leave the page? Any help would be appreciated, thanks.
|
|
|
|
|
hi there,
To alert when leaving the page, u have to put a snippet code of JS for page's unload event
<< >>
|
|
|
|
|
How do I use the OnUnload event? Can you give me an example? Thanks.
|
|
|
|
|
|
Thanks for the tip, but I was hoping for something in C# that I can put in the codebehind in my page.aspx.cs file because I need to access items in my HashTable to display in the message.
|
|
|
|