|
Requirement: ServerName and InstanceName to be displayed in a ToolPart
Data: The classes required to retrieve the DataSource(this contains the server name and instance name used in the connection string) using ASP.NET are, SqlConnection, SqlCommand
Solution:
public string RetrieveDataSource<br />
{<br />
get<br />
{<br />
SqlConnection sqlConnection = new SqlConnection(this.CurrentConnectionString);<br />
SqlCommand sqlCmd = new SqlCommand();<br />
sqlConnection.Open();<br />
sqlCmd.Connection = sqlConnection;<br />
return "Server Name :" + sqlCmd.Connection.DataSource;<br />
}<br />
}
Conclusion: The above code returns the DataSource in the following format “MyServerName\SQLInstanceName”
Swetha
modified on Tuesday, April 28, 2009 3:49 PM
|
|
|
|
|
is there a question in there or is this an FYI post?
|
|
|
|
|
I think the Articles section is a better place for this post...
This is a forum: questions>answers...
Therefore, if you already have the connection string(this.CurrentConnectionString), why make all coding just to extract the server name???
|
|
|
|
|
Hello,
I am having problems formatting data in a datagridview and I am hoping someone out there can help me. How can I format data by column in a datagridview skipping the first row and beginning at the second row?
Thank you for reading.
|
|
|
|
|
Why don't you just create an empty first row?
Normally you would do something like:
DataGridViewRow dgvr = dgvPowerSavingsReport.Rows[dgvPowerSavingsReport.Rows.Add()];
instead do:
<br />
dgvPowerSavingsReport.Rows.Add()<br />
<br />
DataGridViewRow dgvr = dgvPowerSavingsReport.Rows[dgvPowerSavingsReport.Rows.Add()];<br />
Hogan
|
|
|
|
|
Thank you for your reply.
I have done this but it is still not working. How I have it set up is I add a new row to the grid before I bind the data. The new row contains combo boxes and these combo boxes hold new field headers. After selecting a new header I have a button that, when the user clicks, is suppose to format the columns based on the new header name. For instance, a date needs to be formatted as mm/dd/yyyy. I also have a method that loops through and stores the names in an array then try and format the columns based of the headers name. This part works but doesn't reformat the date. Any ideas?
|
|
|
|
|
Here is a quick though. Why don't you format the date before you bind the data to the grid. That way it is what you need it to look like and no formatting is required in the grid? If you need to sort still, then make a hidden column of DateTime type and use it for sorting.
Hogan
|
|
|
|
|
Hello,
This is a great thought however I have no idea what fields I will be receiving and how they are named. The tool I am developing will allow me to take any file with any header and standardize it before it goes into a system. The files I receive are really messy and you never know what you are going to get and at what position the headers are in. therefore, I would need to import the dataset into the app, apply the new headers then format. Thanks again for the reply. Any ideas on how I could do this or maybe improve or modify the existing code to get the app to do what I need it to do?
|
|
|
|
|
Hi
I need to transfer some files to my server in a secure way with my application. What I mean with "secure" is login info cannot be exposed by a network sniffer. Data doesn't have to be encrypted but it doesn't actually matter, it can be encrypted too.
I know that FTPS or SFTP can work for me but I need some 3rd party components to use them and I couldn't find a free one. (Well, I need a free one) And I am not capable of writing my own class for FTPS or SFTP.
Thanks.
|
|
|
|
|
I at all!!!
I'm trying to build a text box.
But wndproc event handler never raise a wm_char (code 0x0102) event...
Anyone could help me?
|
|
|
|
|
Alquerque wrote: Anyone could help me?
Use TextBox.
|
|
|
|
|
I want write text in an sdl window for this reason i will to create this control but keypress event need to map keyboard so i'll try to use wndproc...
|
|
|
|
|
Hi Dear
I use VS2005 , in windows app i want to have a thousand separator for numbers that shown in Textbox or MaskTextBox.
How can i do that?
|
|
|
|
|
thousand separator means ??
Do you want to create a custom textbox control??
|
|
|
|
|
Either use string.Format() or numberVariable.ToString(string formatString) to set the text for the TextBox
myTextBox.Text = string.Format(formatString goes here, numberVariable);
myTextBox.Text = numberVariable.ToString(format string goes here);
I'll leave you to look up format strings in MSDN.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
hi everybody
i have a database named 'example',which is created in sql server 2000
now i want to convert it into msaccess 2007 through C# coding
hope you help me in this issue
thnx in advance
nagendra kumar
|
|
|
|
|
Generate a lot of inserts and execute them with a dataAdapter...
|
|
|
|
|
I need to create control that accepts rtf and draws it. Problem is that drawstring takes only regular text and I cant find anywhere how to draw rtf. Any sugestions are welcome and appreciated...
|
|
|
|
|
draw rtf
Have a look at 'RichTextBox' (that's a standard control)
|
|
|
|
|
Yes I know about richtextbox.. and load and save rtf etc. Please read post again. I need to draw rtf on user control. But thanks anyway.
|
|
|
|
|
You'll have explain a bit better what you mean with 'draw rtf'.
I don't really see the point in actually painting the text onto a usercontrol when the richttextbox (that you can drop onto a usercontrol) would accomplish all this for you. (if you don't want users to alter the text just set it to disabled or read-only)
|
|
|
|
|
Try using RichTextBox.DrawToBitmap, then rendering the bitmap. It's not perfect (it only draws the borders of embedded images), but suffices for a managed solution. I think you could use a method which draws a window (and by extension, control) image to a HDC, but I can't remember the name right now
|
|
|
|
|
Hi,
Conceptually OK, however a few days ago I learned RichTextBox.DrawToBitmap() does not really work.
I solved that by creating my own method, based on FormatRange, see here[^].
|
|
|
|
|
That's very clever. Did you print to another HDC instead of the one given by PrintPageEventArgs, or use another method?
|
|
|
|
|
public void DrawToBitmap(Bitmap bitmap) {
RECT rectToPrint;
rectToPrint.Top = 0;
rectToPrint.Bottom = (int)(bitmap.Height*anInch);
rectToPrint.Left = 0;
rectToPrint.Right = (int)(bitmap.Width*anInch);
RECT rectPage;
rectPage.Top = 0;
rectPage.Bottom = (int)(bitmap.Height*anInch);
rectPage.Left = 0;
rectPage.Right = (int)(bitmap.Width*anInch);
Graphics g=Graphics.FromImage(bitmap);
IntPtr hdc = g.GetHdc();
FORMATRANGE fmtRange;
fmtRange.chrg.cpMax = -1;
fmtRange.chrg.cpMin = 0;
fmtRange.hdc = hdc;
fmtRange.hdcTarget = hdc;
fmtRange.rc = rectToPrint;
fmtRange.rcPage = rectPage;
IntPtr res = IntPtr.Zero;
IntPtr wparam = IntPtr.Zero;
wparam = new IntPtr(1);
IntPtr lparam= IntPtr.Zero;
lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
Marshal.StructureToPtr(fmtRange, lparam, false);
res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);
Marshal.FreeCoTaskMem(lparam);
g.ReleaseHdc(hdc);
}
|
|
|
|