|
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!
|
|
|
|
|
I assume you've got a monitor that's mounted at 90 degrees?
A far easier solution would be to use the graphics drivers - most modern nVidia drivers have an option to rotate the desktop so you can mount a monitor in "portrait" orientation
|
|
|
|
|
If you must rotate the form and not the display, i would suggest creating your own controls and handling the paint function yourself. that way you can draw them however you please. in regards to the form, you could remove the form border. and again draw your own window handle where you choose
|
|
|
|
|
Hi Guys,
I am writing an application that logs to a website and read its contents. Log in page of a web i am trying to connect is as follow:
<br />
<html><br />
<head><br />
<script type="text/javascript"><br />
document.cookie="ttAuthInfo=; expires=Sat, 03-Jan-70 00:00:01 GMT";<br />
document.cookie="ttloggedoff=t";<br />
function doSubmit()<br />
{<br />
document.cookie='ttloggedoff=f';<br />
try<br />
{<br />
if (window.parent&&window.parent.opener&&window.parent.opener.document&&window.parent.opener.document.LoginForm&&window.parent.opener.document.LoginForm.ttAuthUID)<br />
{<br />
window.parent.opener.document.LoginForm.ttAuthUID.value = document.LoginForm.ttAuthUID.value;<br />
window.parent.opener.document.LoginForm.ttAuthPWD.value = document.LoginForm.ttAuthPWD.value;<br />
document.LoginForm.RequestURL.value="StdPage&Template=loginformcln";<br />
}<br />
}<br />
catch( er )<br />
{<br />
}<br />
return true;<br />
}<br />
</script><br />
</head><br />
<body><br />
<form name="LoginForm" method="post" action="tmtrack.dll?LoginPage" onsubmit="return doSubmit()"><br />
<input type="hidden" name="RequestURL" value=""><br />
User<input class="frmTxt" type="text" name="ttAuthUID" size="35"><br><br />
Password<input class="frmTxt" type="password" name="ttAuthPWD" size="35"><br><br />
<input type="submit" name="Submit" value="Login"><br />
</input></br></input></br></input></input></form></body><br />
</html><br />
I know that by writing code like following would make it for me:
HttpWebRequest request;
HttpWebResponse response;
CookieContainer cookies;
string url = string.Format("http://site.com/login?.login={0}&passwd={1}", cboUserName.Text, txtPassWord.Text);
request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
request.CookieContainer = new CookieContainer();
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode != HttpStatusCode.Found)
{
response.Close();
request.KeepAlive = false;
return;
}
cookies = request.CookieContainer;
response.Close();
request = (HttpWebRequest)WebRequest.Create(http:
request.AllowAutoRedirect = false;
request.CookieContainer = cookies;
response = (HttpWebResponse)request.GetResponse(); using (Stream s = response.GetResponseStream())
{
StreamReader sr = new StreamReader(s);
string line;
while (!sr.EndOfStream)
{
}
Can anyone please tell me in my case what would be url ?
I am new to this; Any help would be appreciated.
Thanks,
AksharRoop
|
|
|
|
|
The URL will be completely dependant upon how the site works. In the example above you are using 2 QueryString parameters of 'login' and 'password'. So, if the site has been created to expect and to handle those parameters then it should work as is. If not, then this approach won't work at all. Another way of doing it would be to programmatically fill in the HttpRequest's Form elements (usually a username textbox and a password textbox) and hand-craft the Request data to be in a manner that the site expects. Doing something like that takes a very in-depth knowledge of Web technologies, specifically the HttpRequest and HttpResponse objects and the HttpRequest's Form values. You're basically doing programmatically what the browser normally does. I've had to do it this way before and it is not an easy undertaking. In my case, I had to use a free Java product called WebScarab while browsing the site normally (in my browser) to capture the Request/Response traffic. Then, I was able to use that information to construct the Request data in exactly the same manner as my browser, but filling in a different username and password. The HttpRequest only takes the request data in binary, so you'll have to take the Request text that you construct (after filling in the username and password) and convert it to a byte[] and that will be the Request data. You also have to take into consideration that you'll be sending the Request to some sort of Login page and that the site will probably redirect to another page if the login is successful. One other small note, when working with the Request data be sure you add the CookieContainer to the Request before you do anything with the Request stream, as I found out the hard way that adding the CookieContainer after closing the Request stream does not produce any kind of error, but the Cookies are not included in the Request and since ASP.NET mostly uses Cookies for SessionID you'll probably get some very unexpected results.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
is there any code that shows transaction history of an sql ldf file.(log file of sql) For example
10.01.2009 12:00:43 transaction=update , old value= george, new value=jack
10.01.2009 12:00:56 transaction=update , old value= marry, new value=hillary
I need also date, do you advice any software i am writing this here because you coders know softwares very well. I used apex sql but it gave some errors. I was adviced luminent log explorer but i couldnt find it. My system is sql server 2005. You can also give me some codes to be used in sql query analyzer.
|
|
|
|
|