Click here to Skip to main content
16,018,158 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have a windows form which deals with database coding.
its quite simple code but it takes almost 4 sec to complete. but i want to show wait cursor or app starting cursor is the code is stated and the cursor with be back to default arrow if the code ends.
my code is like this
bool IsMatchedFound = false;
                   SqlConnection con = new SqlConnection();
                   con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\project\sample project\prject xample2 perfect\login\Database1.mdf;Integrated Security=True;User Instance=True";
                   try
                   {
                       con.Open();
                       string qry1 = "Select * from Table1 WHERE password = @password COLLATE SQL_Latin1_General_CP1_CS_AS and Username=@Username COLLATE SQL_Latin1_General_CP1_CS_AS";
                       SqlCommand com = new SqlCommand(qry1, con);
                       com.Parameters.AddWithValue("@Username", this.usernamelabel.Text);
                       com.Parameters.AddWithValue("@Password", this.textBox1.Text);
                       SqlDataReader dr = com.ExecuteReader();
                       while (dr.Read())
                       {
                           if (dr.HasRows == true)
                           {
                               IsMatchedFound = true;
                               break;
                           }
                       }

                   }
                   catch (Exception)
                   {
                       MessageBox.Show("Error with the databse connection");
                   }
                   con.Close();
               }
               catch (Exception ex)
               {
                   MessageBox.Show(ex.ToString());
               }
Posted
Comments
shaikh-adil 1-Dec-12 13:21pm    
brother.. what sir told about this?
sariqkhan 1-Dec-12 13:30pm    
nothing
appreciation with your code

Hi,

Try this:
C#
this.Cursor = Cursors.WaitCursor;

More about cursors in C# Windows Forms: http://www.c-sharpcorner.com/uploadfile/mahesh/cursors-in-C-Sharp/[^]

Hope this helps.
 
Share this answer
 
v3
Comments
shaikh-adil 1-Dec-12 13:28pm    
+5sir, nice answer.
Thomas Daniels 1-Dec-12 13:29pm    
Thanks!
sariqkhan 1-Dec-12 13:29pm    
thanks
+5
:)
Thomas Daniels 1-Dec-12 13:33pm    
Thanks!
sariqkhan 1-Dec-12 16:34pm    
you are welcome sir
thanks to you for helping us
:)
hi dear,

//cursor activities is wait cursor
Cursor = Cursors.WaitCursor;

//cursor activities is default.
Cursor = Cursors.Default;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900