|
i would rewrite it as following:
<br />
public static class MyClass<br />
{<br />
<br />
public static string ConnectionString {<br />
get {return ConfigurationSettings.AppSettings["sConnectionString"];}<br />
<br />
}<br />
<br />
public static int ExecuteNonQuery(String sSql)<br />
{<br />
SqlConnection cnn = new SqlConnection(ConnectionString ); <br />
SqlCommand cmd = new SqlCommand(sSql,cnn); <br />
cnn.Open();<br />
int retVal = cmd.ExecuteNonQuery();<br />
cnn.Close();<br />
return (retVal);<br />
}<br />
<br />
}<br />
Now from any calling class you can do the following:
<br />
int result = MyClass.ExecuteNonQuery("SELECT x FROM y WHERE B = C");<br />
string conStr = MyClass.ConnectionString;<br />
if you want the ExecuteNonQuery to return both the result and the connectionstring in once, create some new class that with two properties, Result and ConnectionString, and return that class from the ExecuteNonQuery method.
|
|
|
|
|
I have a listBox with DataSource:
DataTable dt;
...
listBox1.DataSource = dt;
listBox1.DisplayMember = "value";
listBox1.ValueMember = "id";
How it is possible to get all selected values?
Because when I try:
listBox1.selectedItems[0].toString(); it returns DataRowView...
I can only get selectedIndeces but how can I retreive a value if I know index?
|
|
|
|
|
listbox1.SelectedItems[0] returns a ListItem in ASP.NET in which you can get it's value by listbox.SelectedItems[0].Value. And in Win App it returns an ObjectCollections, which could indead be a DataRowView.
So how to get the info from a DataRowView?
try the following
<br />
((DataRowView)listbox1.SelectedItems[0])[0].ToString();
The second index is the cell in your datarowview, so with the following code, you get the first cell of the first selected datarowview of your listbox and convert it to a string.
If that cell contains another object, you will have to cast it again.
|
|
|
|
|
Thank you very much.
I've tried to do it by deselecting items (SetSelected method) and using SelectedValue property...but your way is much more better. Thanks.
|
|
|
|
|
|
I know system.web.mail name space but it does not work every time.
I need more reliable library to do that. If some body knows such dll or windows application, please introduce me.
Thanks
Rastegar
|
|
|
|
|
m.rastgar wrote: I know system.web.mail name space but it does not work every time.
I need more reliable library to do that.
Could I suggest that it isn't the classes in the namespace that are unreliable but something else, for example your network connection or email server, etc.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
|
my problem is how can i tracks a server's response times and records the results of all monitoring requests into its built-in database. using Historic monitoring data and can analyzed for uptime/down time reports and trend analysis.
|
|
|
|
|
First of all there are companies that check ur site for up and down time, for example http://www.siteuptime.com/[^]
You can also write your own app, that connects every X seconds to your website, and tries to open some page. Add some timers to the app, and store the info in some database. The only problem you have is that maybe you desktop app that checks ur website is behind a not so reliable internet connection, or a slow internet connection. This might blur the results.
|
|
|
|
|
hi to all,
i have to move a word document from one directory to another, but if the document is open i can't move it.
how can i close the document before i move it (i have no instance of word to this document so i can't use the method close(), all i have is the path and the document name)
best regards and thanks in advance
fady
|
|
|
|
|
Well you can first try to move it, if it doesn't move, you can throw some messagebox response asking the user to close the Word file. You can also automatically close the word file, by using the Process class.
Something like
<br />
Process[] p = System.Diagnostics.GetProcessesByName("winword.exe");<br />
for (int i = 0; i < p.length ;i++) {<br />
p[i].Close();
}<br />
|
|
|
|
|
hii.
can we use private static field??
if yes then what is the use odf such field??
|
|
|
|
|
yes you can use it.
The use is e.g. in a singleton class with a getter of the instance
Regards
Hansjörg
|
|
|
|
|
I need to apply acertain style sheet and put table in the body of an email sent using C#.net
this is part of my code
mailMsg .Body += " name: " +
"";
mailMsg .Body +="" + name.Text + "
";
mailMsg .Body +="To: " +
"";
i want something instead of these s
Pride and No
|
|
|
|
|
|
I have posted an article at:
http://www.codeproject.com/useritems/FP_Analysis_Tool_in_NET.asp[^]
If you do not use the demo and want to run the app by building the sources, please install the demo first. Copy the .mdb (database) file from installation folder to the bin/debug and bin/release folders of the sources.
Sorry for the inconvenience.
|
|
|
|
|
I need help. I have a combobox with this code in it:
case 0: MessageBox.Show("Windows Longhorn 1 (1024x768)","Windows Longhorn Cool (1024x768)"); pictureBox1.Image = System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\windows longhorn (1024x768).jpg"); break;<br />
case 1: MessageBox.Show("Windows Longhorn 1 (420x336)","Windows Longhorn Cool (420x336)"); pictureBox1.Image = System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\windows longhorn (420x336).jpg"); break;<br />
case 2: MessageBox.Show("Windows Longhorn Define the digital decade (1024x768)","Longhorn Define the digital decade"); pictureBox1.Image = System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\Windows Longhorn Define the Decade (1280x1024).jpg"); break;<br />
case 3: MessageBox.Show("Windows Longhorn M6 Build Orange (800x600)"); pictureBox1.Image = System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\New Longhorn orange M6 (800x600).jpg"); break;<br />
case 4: MessageBox.Show("Windows Longhorn M6 Build Orange (1024x768)"); pictureBox1.Image = System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\New Longhorn orange M6 (1024x768).jpg"); break;<br />
case 5: MessageBox.Show("Windows Longhorn Home Edition (1600x1200)","Longhorn Home Edition Wallpaper"); System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\Windows Longhorn Home (1280x1024).jpg"); break;<br />
case 6: MessageBox.Show("Windows Longhorn Green Glow (420x336)", "Windows Longhorn Green Glow"); System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\Windows Longhorn Green Glow (420x336).jpg"); break;<br />
<br />
}
WHen I choose an case up to case 4, the image displays in the pictureBox1. But if I choose case 5 or case 6, the image does not show. Why? Could you help me?
In the end we're all just the same
|
|
|
|
|
Case 4 and lower your wrote:
<br />
pictureBox1.Image = System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\New Longhorn orange M6 (800x600).jpg"); break;
case5 and 6 you wrote:
<br />
System.Drawing.Image.FromFile("Themes\\Wallpapers\\Windows Longhorn\\Windows Longhorn Green Glow (420x336).jpg"); break;
You forgot to add pictureBox1.Image = to case 5 and 6
|
|
|
|
|
Well. My mistake.
In the end we're all just the same
|
|
|
|
|
Hello,
I have to do the follwing steps:
1) add controls to a panel programatically
2) make initialization steps in the added control (e.g. add labels) depending on the size
it could be also that the added controls contains other subcontrols for which this steps are also needed...
Normally I think the best way to do that is the Load event, isn't it? But in panel it isn't availaible. What is the best way to solve that?
Regards
Hansjörg
|
|
|
|
|
Put it in the the constructor after Initialize()
|
|
|
|
|
I don't like this solution very much, because a few properties are set after the instantiation. This properties affect the behaviour of the panel.
Regards
Hansjörg
|
|
|
|
|
Maybe hook on to Panel.ControlAdded . The problem is that this one gets fired after the addition of every one of your controls.
|
|
|
|
|
It seems that this is the only solution but it is more work to coding...
Regards and thanks
Hansjörg
|
|
|
|