473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

getting error like cannot implicitly convert type string to bool

Private void butten1.click(object sender,eventArgs e) { if(textBox1.Text="admin") { if(textbox2.text="password"){ form2 f2=new form(); form2.show();} else{ messagebox.show("incorrect password");} while i am run this code i get the error like cannot implicitly convert type string into bool.
May 25 '15 #1
1 1957
computerfox
276 100+
First off, please use the code tags

Second:
Expand|Select|Wrap|Line Numbers
  1. Private void butten1.click(object sender,eventArgs e) { 
  2.  if(textBox1.Text="admin") {
  3.   if(textbox2.text="password"){ 
  4.    form2 f2=new form(); 
  5.    form2.show();
  6.   } 
  7.   else{ 
  8.    messagebox.show("incorrect password");
  9.   }
  10. }
  11.  
Should be:
Expand|Select|Wrap|Line Numbers
  1. Private void butten1.click(object sender,eventArgs e) { 
  2.  if(textBox1.Text=="admin") {
  3.   if(textbox2.text=="password"){ 
  4.    form2 f2=new form(); 
  5.    form2.show();
  6.   } 
  7.   else{ 
  8.    messagebox.show("Incorrect password");
  9.   }
  10. }
  11.  
You can also shorten it a bit with:
Expand|Select|Wrap|Line Numbers
  1. Private void butten1.click(object sender,eventArgs e) { 
  2.  if(textBox1.Text=="admin" && textbox2.text=="password") {
  3.    form2 f2=new form(); 
  4.    form2.show();
  5.   }
  6.   else{ 
  7.    messagebox.show("Incorrect password");
  8.   }
  9. }
  10.  

Hope that helps!
May 25 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
2
by: Jeff | last post by:
I get the following error: Cannot implicitly convert type 'Factory.Stack.pArrayStack' to 'Factory.Stack.StackDefs.ImStack' at compile time. I thought perhaps there was a mismatch between the...
2
by: Patrick Olurotimi Ige | last post by:
When i convert:- this code from VB to C# Why do i get error "Cannot implicitly convert type 'object' to 'bool' VB --- If cmdcommand.Parameters("ReturnValue").Value = 1 Then lblStatus.Text =...
6
by: eric.goforth | last post by:
What's wrong with this? if (bool)(UserIDs == ThisUserId) { return true; }
1
by: rmrao | last post by:
protected override void InitializeCulture() { string culture = ""; culture = Request.QueryString; if (culture = null) culture = "en-US"; ...
3
by: sappyjosh | last post by:
public void Update_Stock(Inseed Is) { if (con.State == ConnectionState.Open) { con.Close(); } try { ...
2
by: vadiraj hebbar | last post by:
public static double reversenumber(double i) { i = 1 * i; if (i < 0) return i.ToString() + "is reverse number"; else if...
4
by: Asma P | last post by:
//declare variable internal bool CheckBox11 = false; if (!string.IsNullOrEmpty(Reader.ToString())) { CheckBoxID = Reader.ToString(); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.