|
Hi Lim,
If you create a timer that ticks every 1 second, and use the code below in the tick event method:
<br />
winFormTimerLabel.Text = System.DateTime.UtcNow.TimeOfDay.Hours.ToString() + " : " + System.DateTime.UtcNow.TimeOfDay.Minutes.ToString()<br />
+ " : " + System.DateTime.UtcNow.TimeOfDay.Seconds.ToString());<br />
I'd imagine it will do what you want.
Cheers,
|
|
|
|
|
System.DateTime.Now.ToString ( "HH:mm:ss" )
|
|
|
|
|
Show off .
|
|
|
|
|
Ha ha! Ha ha! Mine's smaller! ... Oh, wait... 
|
|
|
|
|
Thanks for your efforts guys.
In the end this is what I did.
private Timer Clock = new Timer();//create a timer
void Clock_Tick(object sender, EventArgs e)
{
//refresh the time every 1 second
this.winFormTimerLabel.Text = DateTime.Now.ToLongTimeString();
}
private void Form1_Load(object sender, EventArgs e)
{
Clock.Interval = 1000;//every 1 second do something
//what the program is supposed to do when 1 second elasped
Clock.Tick += new EventHandler(Clock_Tick);
Clock.Start();//starts the timer
}
I finally understood where did I went wrong - I did not put in the interval value and I did not start the timer..... silly me 
|
|
|
|
|
|
keep the code above, just add a timer object!!! edit event tick, and interval propriety.
This will trigger your above code all the time!!! The timer will be refreshed. 
|
|
|
|
|
Hey
I want to execute a code when the dataset position change ,,
thanks,
jooooo
|
|
|
|
|
Have you ever heard of event handlers? You might want to see if there is one that gets triggered when the dataset position changes.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi, i got a access database which i want to use it for my C# application.
I created a new database connection using the Server Explorer -> Data Connections -> Add Connection, then browse for my database file and test connection. Connection Succeded.
I then right click my project -> Add -> New Item -> Dataset. Then i draw all my tables thru the server explorer into the Dataset.
I have 1 table called Staff. I right click the staffTableAdapter -> Add new Query.
SELECT nric, name, [password], dob, address, tel_mobile, tel_home, catalogueAccess, inventoryAccess, orderAccess, adminAccess, staffAccess FROM staff where nric = ? and password = ?
then I name my method name as "ValidateUser".
problem : inside my LoginForm.cs. For the method
private void btnLogin_Click(object sender, EventArgs e)
{
}
What do i code inside here to call my TableAdaptable method "Validate User"
modified on Saturday, August 2, 2008 1:16 PM
|
|
|
|
|
benjamin yap wrote: What do i code inside here to call my TableAdaptable method "Validate User"
Depends. first, you instantiate an instance of the staffTableAdapter , then pass the appropriate parameters to your method. Hard to tell without seeing everything as a whole.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
my dataset is called dsTable. How do i create an instance of the adapter
|
|
|
|
|
benjamin yap wrote: How do i create an instance of the adapter
Something along the lines of staffTableAdapter myAdapter = new staffTableAdapter();
I suggest you read up on how to use table adapters and data sets
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
but i am not using coding base to create my dataset and connection string..i am using the server explorer thing
|
|
|
|
|
What does connection string have to do with it? You asked how to invoke your method, and at that point you have to do some coding. Again, read up on the subject.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Okay
i have created an instance of the staffTableAdapter this way
dsTablesTableAdapters.staffTableAdapter sa = new EBMS.dsTablesTableAdapters.staffTableAdapter();
so i want to call the ValidateLogin method, so i did this
sa.ValidateLogin()
But inside the arguement, it ask me for
dsTables.staffDataTables dataTable,string nric,string password
What do i have to put for the first arguement? they asked for dsTables.staffDataTables dataTable... for the other 2 arguement i out txtnric.text and txtpassword.text
|
|
|
|
|
When you created the ValidateLogin , didn't you make the query take in parameters?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Ok when i created a new Query, they asked me Type of SQL query to use.
SELECT which return rows
SELECT which return single value
UPDATE
DELETE
INSERT
At first, i selected "SELECT which return rows" and they asked for 3 arguement. dataTable, string nric and string password.
So i change to "SELECT which return single value"
string result = sa.ValidateLogin(txtUsername.Text, txtPassword.Text);
MessageBox.Show(result.ToString());
When i key the correct username and password, the messagebox shows the username. If i enter a wrong username and password, the whole program ended and point to my code and says, NullReferenceException was unhandled.
If the correct username was found, i want to store the results of other columm to my variable i declared. Because my staff table have
nric, name, [password], dob, address, tel_mobile, tel_home, catalogueAccess, inventoryAccess, orderAccess, adminAccess, staffAccess
if the username and password matches, i want to store all the values to the variable i create at the top of my LoginForm.cs
private bool catManager;
private bool inventManager;
private bool orderManager;
private bool administrator;
private bool user;
how do i do that?
|
|
|
|
|
benjamin yap wrote: If i enter a wrong username and password, the whole program ended and point to my code and says, NullReferenceException was unhandled.
You trap that exception and that is how you know if the login failed.
benjamin yap wrote: how do i do that?
You should be able to pick the pieces out of the dataset returned by the table adapter.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
may i know wats the code to pick out the pieces of the value? or you provide me with an article on that? cause i dont know wat search term to use
dsTablesTableAdapters.staffTableAdapter sa = new dsTablesTableAdapters.staffTableAdapter();
try
{
string result = sa.ValidateLogin(txtUsername.Text, txtPassword.Text);
MessageBox.Show(result[2].ToString());
this.DialogResult = DialogResult.OK;
i tried result[2] to return the 3 column value. But it return 'M' inside.. because the result gives me the username which is Admin and result[2] = 'm'. the 3rd character.
modified on Sunday, August 3, 2008 2:45 AM
|
|
|
|
|
benjamin yap wrote: sa.ValidateLogin(txtUsername.Text, txtPassword.Text);
Should be returning a dataset, not a string.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
it still wont work.
I change my Query Type to "Select which returns a row (return one or many rows or column)"
Then in my login.cs
DataTable staffdt = new DataTable();
dsTablesTableAdapters.staffTableAdapter sa = new dsTablesTableAdapters.staffTableAdapter();
try
{
staffdt = sa.GetDataByLogin(txtUsername.Text, txtPassword.Text);
//this.DialogResult = DialogResult.OK;
string uname = staffdt.Columns["name"].ToString();
MessageBox.Show(uname);
}
catch(NullReferenceException)
{
MessageBox.Show("Invalid Credentials");
}
take a look at my screen shot.
http://opencube.com.sg/c.GIF
how do i get the value of the returned datatable column by column
|
|
|
|
|
hi friend's
i have an application that work with threading.
in load_form event of the form i create an instance a thread object and run it,
now my problem is , i want to kill the thread on another event such as button_click event on this form and i cant do it.
i can not create my thread public, because the number of thread should be create is not certain in my allpication,
how can i do it, please sya me a solution to solve it...
thanks alot
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
The only reliable way to kill a thread is to let the thread terminate normally.
This means you need a way to notify a thread that it needs to terminate, and
provide a way to wait for the thread to terminate if necessary.
There's synchronization objects you can use. For example, EventWaitHandle.
There's no need to "create my thread public", but you may need to keep contexts
to your created threads somewhere, like in a collection in your form class.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
One way to gracefully terminate a thread is to set a volatile bool variable to some value and check this value inside the other thread, like this:
public void ButtonClickHandler(Object sender, EventArgs args)
{
requestStopThread = true;
}
Inside your thread you need to check if this variable will be set to true and then terminate the thread in a correct way:
while(!requestStopThread)
{
}
or
...
if(requestStopThread)
...
regards
modified 12-Sep-18 21:01pm.
|
|
|
|