| | |
if statement > from1 read from fields..
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 15
Reputation:
Solved Threads: 0
Hello i just started up today with C#,
Im femilair with PHP so i can do some things i have google etc.
But now im stuck.. with this:
I made a form with a user/password fields and a logon button,
and a field that reads from DB. Everything did work, but now i want to make the user/password field active to work (to access the db) not sure how yet.. so if you guys can help me with that also it would be greate!
With this code im getting the error for the if statement i made
(not sure how to fix it properly)
Im not sure if some one can help me out
Im femilair with PHP so i can do some things i have google etc.
But now im stuck.. with this:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace WindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); username.Text = ""; password.PasswordChar = '*'; string loginus = ""; string loginpas = ""; loginus = username.Text; loginpas = password.Text; if (loginus == false) { string MyConString = "SERVER=localhost;" + "DATABASE=ot;" + "UID=" + loginus + ";" + "PASSWORD=" + loginpas + ";"; MySqlConnection connection = new MySqlConnection(MyConString); MySqlCommand command = connection.CreateCommand(); MySqlDataReader Reader; command.CommandText = "select * from players ORDER BY id"; connection.Open(); Reader = command.ExecuteReader(); while (Reader.Read()) { string idPlayers = ""; idPlayers = Reader.GetString(0) + "\t" + Reader.GetString(1); listBox1.Items.Add(idPlayers); } connection.Close(); } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string loginus = ""; string loginpas = ""; loginus = username.Text; loginpas = password.Text; } } }
I made a form with a user/password fields and a logon button,
and a field that reads from DB. Everything did work, but now i want to make the user/password field active to work (to access the db) not sure how yet.. so if you guys can help me with that also it would be greate!
With this code im getting the error for the if statement i made
(not sure how to fix it properly)
Im not sure if some one can help me out
•
•
Join Date: Jul 2008
Posts: 89
Reputation:
Solved Threads: 10
Hi,
In C# if you are gonig to use the == operator its not defined for type string and boll(ie string == bool)but since you are trying to check it the string 'loginus' is not empty you can use one of this options
1. if(loginus != "")
2. if(loginus != string.Empty)
3. if(!string.IsNullOrEmpty())
4. if(string.IsNullOrEmpty() == false)
5. if(string.Count != 0)
All this are valids if statements pick the one you like better.
Regards,
Camilo
In C# if you are gonig to use the == operator its not defined for type string and boll(ie string == bool)but since you are trying to check it the string 'loginus' is not empty you can use one of this options
1. if(loginus != "")
2. if(loginus != string.Empty)
3. if(!string.IsNullOrEmpty())
4. if(string.IsNullOrEmpty() == false)
5. if(string.Count != 0)
All this are valids if statements pick the one you like better.
Regards,
Camilo
•
•
Join Date: Jul 2008
Posts: 15
Reputation:
Solved Threads: 0
•
•
•
•
Hi,
In C# if you are gonig to use the == operator its not defined for type string and boll(ie string == bool)but since you are trying to check it the string 'loginus' is not empty you can use one of this options
1. if(loginus != "")
2. if(loginus != string.Empty)
3. if(!string.IsNullOrEmpty())
4. if(string.IsNullOrEmpty() == false)
5. if(string.Count != 0)
All this are valids if statements pick the one you like better.
Regards,
Camilo
When im trying to send the information from username/password to my MySQL string it just wont refresh from1() anny idea how i should do it? i have it now like this:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace WindowsApplication2 { public partial class Form1 : Form { string loginus = ""; string loginpas = ""; private void button1_Click(object sender, EventArgs e) { loginus = username.Text; loginpas = password.Text; } public Form1() { InitializeComponent(); if (loginus != string.Empty) { string MyConString = "SERVER=localhost;" + "DATABASE=ot;" + "UID=" + loginus + ";" + "PASSWORD=" + loginpas + ";"; MySqlConnection connection = new MySqlConnection(MyConString); MySqlCommand command = connection.CreateCommand(); MySqlDataReader Reader; command.CommandText = "select * from players ORDER BY id"; connection.Open(); Reader = command.ExecuteReader(); while (Reader.Read()) { string idPlayers = ""; idPlayers = Reader.GetString(0) + "\t" + Reader.GetString(1); listBox1.Items.Add(idPlayers); } connection.Close(); } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } } }
![]() |
Other Threads in the C# Forum
- Previous Thread: Regex help
- Next Thread: Reading XML file
| Thread Tools | Search this Thread |
.net access algorithm array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml






