|
if by using return it goes back to where the loop is..
i wanna break out of that loop and exit the program.. or is there a way to clear all the input in the program
|
|
|
|
|
You can explicitly terminate a console app by calling Environment.Exit() . Look at this:
using System;
class Class1
{
public static int Main(string[] args)
{
Console.WriteLine("Hello");
Environment.Exit(0);
Console.WriteLine("Bye");
return 0;
}
}
However, I do not know how 'safe' it is to call that method. HTH.
Cheers,
Vikram.
http://www.geocities.com/vpunathambekar
Google talk: binarybandit After all is said and done, much is said and little is done.
|
|
|
|
|
not sure of your explanation
if you are trying to break a loop, i *really* dont like he break keyword except for switch (but that is just me) i like o gracefully exit a loop like this
<br />
bool found = false;<br />
<br />
while(!found )<br />
{ <br />
if(condition)<br />
{<br />
found = true;<br />
}<br />
}<br />
<code><br />
<br />
hth<br />
g00fy<br />
<br />
-- modified at 5:13 Friday 16th September, 2005
|
|
|
|
|
in C# webform i get the value in javascript ,i want send value to next webform through the javascript
m mohamad rafi
|
|
|
|
|
Put the value in a hidden field.
---
b { font-weight: normal; }
|
|
|
|
|
The program is to use PocketPC to connect the web service and get the dataSet and display to dataGrid.
But I can't find method like "setDataBind", how to show the dataSet to DataGrid??
The code is as follow:
private void button1_Click(object sender, EventArgs e)
{
localhost.Service service = new DeviceApplication2.localhost.Service();
service.BeginEmployeeDataSet(new System.AsyncCallback(WriteDataSet), service);
}
private void WriteDataSet(System.IAsyncResult oRes)
{
localhost.Service service = (DeviceApplication2.localhost.Service)oRes.AsyncState;
System.Data.DataSet ds = service.EndEmployeeDataSet(oRes);
}
|
|
|
|
|
You should use
DataGrid.DataSource = dataSet;
Live Life King Size
Alomgir Miah
|
|
|
|
|
I'm tring to think of a fast way to perform a string search on a treeview. I'm reading in a hierarical CSV file and inserting it into a tree for easy viewing. For some elements of my code I need to find "needle" in this giant haystack. I've thought of extending the treeview to integrate with a ternary search tree of some sort, but that seems really complicated to me. Linear searches of the tree seem like a really bad idea considering my CSV is in upwards of 9,000 lines. It's a lot of data so I need a fast way to search. I'd prefer to have an array with the keys indexed as unique strings. Good/bad idea? I'm pretty new to c# and this is proving much more difficult than I thought it would.
Any suggestions or examples would be greatly appreciated!!
|
|
|
|
|
I found this on the msgboard - any other suggestions or is there a faster way?
http://www.codeproject.com/script/comments/forums.asp?msg=1164592&forumid=1649&ForumID=1649&XtraIDs=1649&searchkw=treeview&sd=6/17/2002&ed=9/15/2005&Page=2#xx1164592xx
|
|
|
|
|
|
I think the problem is in setting the bool. But obviously I don't really know
or I wouldn't be posting this......thanks...
public class Form1 : System.Windows.Forms.Form
{
//member fields.....
public Complex2 complexA;
public Complex2 complexB;
public bool bShowValue;
Pen activePen;......
///////////////////////////////////////////////////////////////////////////////
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
DoThis(e.Graphics);
DoThat(e.Graphics);
if(bShowValue)
{
DrawComplexNumber(this.CreateGraphics(), activePen, this.complexA.Real, this.complexB.Imaginary) ;
}
////////////////////////////////////////////////////////////////////////////////
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen activePen = new Pen(Color.Coral, 4);
try
{
bool bShowValue = true;
this.complexA.Real = Convert.ToDouble(this.textComplexAReal.Text);
this.complexB.Imaginary = Convert.ToDouble(this.textComplexAComplex.Text);
DrawComplexNumber(g, activePen, complexA.Real, complexA.Imaginary);
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void DrawComplexNumber(Graphics g, Pen activePen, double re_, double im_)
{
g.DrawLine(activePen, (xIndent + graphRect.Width/2), (yIndent + graphRect.Height/2),
(xIndent + graphRect.Width/2) + (float)(re_ * xIndent), (yIndent + graphRect.Height/2) - (float)(im_ * yIndent));
}
private void button1_Click(object sender, System.EventArgs e)
{
Invalidate();
}
|
|
|
|
|
Anonymous wrote:
Graphics g = this.CreateGraphics();
Pen activePen = new Pen(Color.Coral, 4);
What on earth is this ? You should do ALL drawing in your paint method
What does 'blows sky high' mean ? It would help if you told us the actual error, and the line that causes it. Best guess, based on a lack of info, is that your convert.todouble call fails because a text box is empty, or contains a string that can't convert into a number.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sorry about that...I thought that this code was an earlier version that I was running....
This code compiles/runs-- but it needs to be debugged. I'm still learning
how to navigate the debugger.
Problem_1: I enter NUMBERS(not letters etc...) into the text boxes and hit OK button--> Keep getting the MessageBox in the catch block.
i.e. bShowValue = false; ALL the time.
Problem_2.
What on earth is this ?
I see your point. I'm out of scope?
If all drawing must be in paint method, perhaps it would be best to create an
array of pens INSIDE the paint method inside a for(...) loop? No?
|
|
|
|
|
Anonymous wrote:
Problem_1: I enter NUMBERS(not letters etc...) into the text boxes and hit OK button--> Keep getting the MessageBox in the catch block.
i.e. bShowValue = false; ALL the time.
Use F9 to set a break point at the start of the function. Make sure you're in debug mode ( Build/Configuration Manager ), then hit F5 to start debugging. I believe it's F5 also to step to the next line, a right click will give you the option and show you the keys in any case.
Anonymous wrote:
If all drawing must be in paint method, perhaps it would be best to create an
array of pens INSIDE the paint method inside a for(...) loop? No?
Your paint method should be able to tell via a flag if it should draw a number, then call the draw method that you're calling now. Why do you need an array of pens ? If they are always the same, one pen should be a member variable ( which means you need to impliment IDisposable and dispose of it )
Christian Graus - Microsoft MVP - C++
-- modified at 22:56 Thursday 15th September, 2005
|
|
|
|
|
Christian Graus wrote:
If they are always the same
They're not.I need many different colored lines, so each button click that is associated with the text boxes--> btn OK needs to effectively fire
g.DrawLine... w/ a different color.
thanks for your help! I will work on this....I'm sorry I'm so disorganized but I'm trying to learn this by trial and error....
|
|
|
|
|
Anonymous wrote:
They're not.I need many different colored lines, so each button click that is associated with the text boxes--> btn OK needs to effectively fire
g.DrawLine... w/ a different color.
It cannot work that way. You will need to store the information about what you want to draw, so that your paint handler can draw them correctly.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The problem is that you are throwing away all the information about the error. You are catching all possible exceptions and assumes that there is only one possible cause for the error.
If you want to catch the exception that occures when someone writes an illegal number, you should catch only that specific exception (FormatException). Although the better approach is to validate the data instead of using exceptions. Exceptions should only be used for errors that you can't handle, and faulty input is very much possible to handle.
Use the Double.TryParse method to make an attempt to parse the value. If the return value is false, the input is faulty, and you can very gracefully display the error message.
---
b { font-weight: normal; }
|
|
|
|
|
I'm trying to learn how to use the debugger.
I have the Watch Window out but it I can't seem to get any variables into it.
If I click on it it just turns blue.
If I copy the variable and the right-click paste into the window-- nothing...
help-- thanks
(Debugger is in "run", a breakpoint has been set..)
help! thanks...
|
|
|
|
|
The watch window has tabs on the bottom. Click Immediate ( from memory ) to enter variables, otherwise it shows you what it can see in the current scope.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have written code with a single database table with front end in c#.
I am able to make changes in table by using the update statment. But after i exit out of the application I am not able to login with the same user name and pwd that I could before.
Pasting my login page code and the update query code...can anyone help me plz
private void button1_Click(object sender, System.EventArgs e)
{
try
{
oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "Select User, PIN
from BankAccount where User = '" + UsertextBox.Text + "'"+
" And PIN= '" +
PINtextBox.Text + "'";
oleDbDataAdapter1.Fill(dataSet1);
DataTable datatable=dataSet1.Tables[0];
if(UsertextBox.Text == (string)datatable.Rows[0][0] && PINtextBox.Text== (string)datatable.Rows[0][1])
{
string user= UsertextBox.Text;
AccountForm Af = new AccountForm(user);
Af.Show();
}
else
{
label1.Text="Invalid User Name or Password";
}
}
catch(System.Data.OleDb.OleDbException ole)
{
MessageBox.Show( ole.ToString());
}
finally
{
oleDbConnection1.Close();
}
}
And in the second form I have this Update query method
private void button3_Click(object sender, System.EventArgs e)
{
try
{
oleDbConnection1.Open();
if( Acc_textbox.Text != " ")
{
int creditbalance = Int32.Parse(textBox3.Text);
//label7.Text=creditbalance.ToString();
oleDbDataAdapter1.UpdateCommand.CommandText=
" Update BankAccount SET " +
"FirstName = '" + textBox2.Text+
" ', LastName ='"+ textBox1.Text+
"', IntialBalance = " + creditbalance+
" , PIN ='"+ textBox4.Text+
" ', PhoneNumber= " + Int32.Parse(textBox5.Text)+
" , Address ='"+ textBox6.Text+
" ', City ='"+ textBox7.Text+
" ', State ='"+ textBox8.Text+
" ', SSN ='"+ textBox9.Text+
" ' where User = '" + Acc_textbox.Text + "'";
statustextbox.Text += "\r\n Sending Query "+
oleDbDataAdapter1.UpdateCommand.CommandText + "\r\n";
oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery();
statustextbox.Text +="\r\n Query Successful";
}
else
statustextbox.Text +="\r\n Query not Successful";
}
catch(System.Data.OleDb.OleDbException ole)
{
statustextbox.Text += ole.ToString();
}
finally
{
oleDbConnection1.Close();
}
}
|
|
|
|
|
What does your database look like at the end ? Has your username/password been changed or lost entirely ?
Why on earth do you have only one table ? You may as well persist to XML if you're going to do that.
Your code is also extremely vunerable to SQL injection attacks. Using stored procedures instead of this sort of SQL on the fly generation would help your overall design, but would not be enough by itself to provide protection from attacks.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm a C# noob so I apologize if I say something stupid or unclear.
I have a class that contains a thread that sits there in a loop, considering the world. Every once in a while, it decides that it needs to alert the world to some idea it has, so it calls its delegate function, sends information to all of its clients, who get the information via event handler functions that they've "+="'d to the delgate.
If this class didn't incorporate a thread, I would be done here, and everything would work perfectly. My class's clients would add a handler to the class's delegate when they feel like listening to it jabber, and they would periodically receive data and do whatever they want with it.
The terrible problem is that you can't ordinarily mess with controls if you aren't in the control's originating thread, so you need to use "Invoke".
If I understand correctly, one way to deal with this would be to have all the clients realize they are dealing with a class that is kind of toxic, and have all handlers that sign up with my class call "Invoke" whenever they are called. Essentially, the clients would realize that they are operating from within a foreign thread, and they would take appropriate precautions.
I don't like this solution, because the clients shouldn't have to know that they are being called from a different thread. They should just be able to add a handler and get data from the class, and everything should work.
Also, I could have some performance issues here, since future instances of my class might not use a thread, and I'd be stuck with all of this old ugly code that uses "Invoke".
Another way to deal with this is for the class itself to use "Invoke" on the delegate. I haven't thoroughly tested this, but it compiles and apparently runs, at least when there is only one client.
The drawback to this is that when I create the class, I have to pass in the form that created the class, so there will be an object to use to call invoke. This is ugly, and also I expect it would mess up if another thread added a handler to my class.
Question:
What is the best way to deal with events that are generated from within a thread, so that the clients work correctly, don't have to know that they are dealing with a thread, and don't have to pass difficult to explain parameters around?
Thank you,
bruce
|
|
|
|
|
Can I just use the "BeginInvoke" method on the delegate, and dummy out the 2nd and 3rd parameters? This is what I'm doing now, and it also compiles and runs.
bruce
|
|
|
|
|
Okay, this idea is wrong, I can see it coming in on a different thread.
bruce
|
|
|
|
|
You can subscribe to an event from a different thread. You just cannot use a System.Windows.Forms.Control from a thread other than the UI thread.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|