|
thanks a lot......
but single slash \ shown error again......
used \\ and executed sucessfully
thank uuuuu
the quieter u become more u hear
|
|
|
|
|
Actually you have to escape the parenthesis in the regular expression, not the string. Put a backslash in the pattern:
s = Regex.Replace(s," \\( ", " ");
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Or you could use the verbatim operator
s = Regex.Replace(s, @"\(", " ");
Saves one escaping.
|
|
|
|
|
Hi,
I'm making a thread that generates random numbers into an array. Then I make 2 threads from that one I made, but I get the same random numbers in each thread. I've tried to use lock or Monitor, what am I doing wrong?
the C# girl
|
|
|
|
|
Hi,
could you please provide the code you are using to create the random numbers? Maybe you are using the same seed for the creation of the numbers, but that's something that can be seen in the code.
Regards
Sebastian
|
|
|
|
|
Hi,
I've just got!!!
I put static in front of the "Random random = new Random();" not private/public and know it works. Thanks.
|
|
|
|
|
Well, you're welcome...
|
|
|
|
|
Do you know why it didn't work first?
The Random class uses the current time as the "seed" for generating random numbers. Because you created two instances, one for each thread, and the two threads started running in parallel right away, both of them got the same seed and therefore generated the same sequence of random numbers.
BTW, the MSDN doc says that instance methods on the Random class are not thread safe - you might have to look out for that.
|
|
|
|
|
Hi all,
If I have a SqlCommand of which the query includes a join, let's say something as follows:
SELECT * FROM Stock INNER JOIN Transactions ON Stock.StockID = Transactions.StockID
how can I use SqlDataReader[string name] to obtain values from the result coming from a specified field in a specified table? In other words, if both the tables Stock and Transactions include a field with the name Price , the result in SqlDataReader will include two columns, both named Price . If I want to compare the two for instance, how can I force SqlDataReader[string name] to return Stock.Price or Transactions.Price ?
I was hoping for something like:
using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
{
while (sqlDataReader.Read())
{
if (sqlDataReader["Stock.Price"] != sqlDataReader["Transactions.Price"])
ShowError("Item was sold at incorrect price");
}
}
This is a simple example but I hope you get the point. I'm hoping that it isn't necessary to change my SQL query so as to give explicit names to the different columns.
|
|
|
|
|
Hi Dewald,
i'm surprised that the query can be executed with two tables containing a column with the same name. AFAIK you have to rewrite your query to give the two columns explicit names. If I understood the concept of datareaders right, the reader doesn't know that the query contains two tables. For him it is only one table (more like a view).
If there is another solution than rewriting the query, i would be very interested to hear about.
Regards
Sebastian
|
|
|
|
|
Dewald wrote: other words, if both the tables Stock and Transactions include a field with the name Price, the result in SqlDataReader will include two columns, both named Price
AFAIK, that wouldn't be possible. Since the Item is an indexer to the column list, there cannot be multiple instances with exactly the same name (which one would the indexer return or how would you refer to the other one, price or price ).
I think the reader works as other classes in the SqlClient so it will add an ordinal number to the end of the column if several columns exists with the same name. So I guess your other column is Price1. The downside is that you cannot be sure which one it is.
Dewald wrote: sqlDataReader["Stock.Price"]
Single Item is not structural so the dot notation in this case wouldn't have any meaning if structure is considered (although the name of a column can contain a dot).
So after all, the most reliable way is to rewrite the sql. One idea could be that you include your logic (Stock.Price != Transactions.Price) to the sql statement itself using CASE and perhaps event use the condition in where logic (depending what you want). This way your program would have more prepared results and it would be easier to investigate them and perhaps the amount of rows returned would be smaller. But all of this depends on your requirements and logic.
|
|
|
|
|
Mika Wendelius wrote: AFAIK, that wouldn't be possible. Since the Item is an indexer to the column list, there cannot be multiple instances with exactly the same name (which one would the indexer return or how would you refer to the other one, price or price ).
OK thanks, at least I can stop trying to make it work now. Guess I'll just have to rewrite the SQL to give the columns explicit names.
However...
Mika Wendelius wrote: One idea could be that you include your logic (Stock.Price != Transactions.Price) to the sql statement itself using CASE and perhaps event use the condition in where logic (depending what you want).
Of course! Excellent suggestion. In this instance it is actually exactly what I need and should have done from the start. For future problems where this wouldn't suffice I will just rewrite the SQL though.
Thanks for the help.
|
|
|
|
|
You're welcome, glad if it helped
|
|
|
|
|
Hi all
I have created an application windows using c#
In that i want to save the image in Image folder which i created in my application....
now when i save its going to default location
ie \bin\Debug/ImageName...
how can i save the image in my Image folder inside the application ?
can anybody help me?...
|
|
|
|
|
do you have your image as an Image class?
if so just use Image.Save(Application.StartupPath + "\\Images\\Image1.png");
or whatever file path you want to use
|
|
|
|
|
If i give this it is going to same debug\bin\Images\myimage
|
|
|
|
|
what do you mean 'image forlder you created in your application'?
did you create a folder using the application?
if so then you can change the file path in the code i gave to what ever file path you want, drop the application.startuppath if you need to.
or do you mean you have a folder in your 'project' that you want to save the images to.
the application once compiled does not contain folders.
and i very 'almost' 100% sure you can modify your application while its running.
what exactly do you want to do?
|
|
|
|
|
ya u r correct...
I have an imagefolder which i created directly....not through code...
is it possible to save my image to tht folder?...or any other option to create a folder through code and save it in that...
am new to c#
thanks in advance
|
|
|
|
|
In my opinion your best option would be to create the folder through code.
lets say you want a folder on the C Drive for example you would code something like this:
System.IO.Directory.CreateDirectory("C:\\MyNewFolder");
then you can access that with the same code as previously given.
There are also ways to access the current path of system folder such as 'Program Files' and 'Desktop' but i cant remember that of the top of my head, you will have to look at that if you need something like that.
And remember not all computer will be setup the same. Some may not have a C Drive for instance
P.S. you can access any folder that you know the full path of
|
|
|
|
|
|
Hi,
i wanted to ask if there is a way to catch the line-out signal in c# so that i am able to stream the signals, without using a hardware solution like a adapter.
For example:
I am playing music using winamp (output on the soundcard, line-out) and at the same time i am streaming the sound in a network, but the audio source has to be the line-out output.
thanks, greetings
|
|
|
|
|
Hi,
I need some help with an installer component. In the Install method I open a configuration form that I created which returns OK or Cancel as dialog results. I found on some site that if I want to cancel the installation, I have to throw an InstallException. At first, the setup wizard displayed a message box saying about an error with the code 2869. I don't really think there is any difference in the source code, but now I get the same message box, followed by another message box with no message. Do I need to install some service pack that supports cancelling the installation? Or does anyone know another way? A site with a tutorial for installer components would also be helpful (google didn't help much, or I didn't use the right keywords)
I also tried using a NoImpersonate.js script file with a post build event. Didn't work. I tried running a .bat file containing "msiexec /i pathtofile.msi" with admin privileges. Still 2869. I read that this only happens on Vista ... I managed to get the same error on XP too )
And yes I am running the setup.exe file, not the msi.
Thank you
|
|
|
|
|
Hello
This error generally occurs when custom action fails to perform its action with "Elevated Privileges" on Vista (which is a normal case). The solution is NoImpersonate.js but you are saying that it couldn't solve the problem. So can you tell me when exactly this message box appeared? I mean as soon as you ran exe or after completion of the "install" event i.e after welcome message window?
One more thing. Have you used installer class to override custom action?
Also are you passing the "Property" (i.e. value) consisting of Ok or Cancel to custom action? "Savedstate" and "idictionary" is used to do it.
|
|
|
|
|
The message box appears when I click the Cancel button on my form.
This is the code inside the overridden Install method:
Config config = new Config();
if (config.ShowDialog() == DialogResult.Cancel)
throw new InstallException("Installation aborted"); //I think this is why the error message is displayed.
base.Install(stateSaver);
where Config is the configuration form that I created.
Can you tell me how to use SavedState and IDictionary to pass OK or Cancel to the custom action?
|
|
|
|
|
Hi,
I have a problem. I have a form in c#, with buttons, controlls, textBoxes and others, which I need to rotate 90 degrees. Is this posible in c#?
Can the form be rotated and with it, it's all content, or maybe just the content to be rotated? Buttons, textboxes, checkboxes, labels, can be rotated?
Or maybe this is posible in WPF?
Any ideas?
Thanks!
|
|
|
|