Omer Butt
Active member
- Joined
- Sep 6, 2021
- Messages
- 29
- Programming Experience
- Beginner
Please Tell me if the Line 13 `if (Txt_AddUser_UserName_TextChanged(sender, e) == true)` is now a write way then how to write it.
Add User and Check for User Exist:
//This part to add a user in database as a signup in Line 13 in the condition of if I tried to create a logic if Txt_AddUser_UserName_TextChanged(object sender, EventArgs e) this is true only than it sign up otherwise throws an error. Butt In this Line I came across this error, CS0019 Operator '==' cannot be applied to operands of type 'method group' and 'bool'
private void Btn_SignUp_Click(object sender, EventArgs e)
{
String Role = Combo_UserRole.Text;
String Name = Txt_AddUser_Name.Text;
String DOB = DatePicker_AddUser_DOB.Text;
Int64 Mobile = Int64.Parse(Txt_AddUser_MobileNo.Text);
String Email = Txt_AddUser_Email.Text;
String UserName = Txt_AddUser_UserName.Text;
String Password = Txt_AddUser_Password.Text;
try
{
if (Txt_AddUser_UserName_TextChanged(sender, e) == true) //Error is in this Line
{
Query = "insert into Users_Table (User_Role,User_Name,DOB,User_Mobile,User_Email,User_Username,User_Password) values('" + Role + "','" + Name + "','" + DOB + "','" + Mobile + "','" + Email + "','" + UserName + "','" + Password + "')";
SqlCommand cmd = new SqlCommand(Query, Conn.Connect);
Conn.OpenConnection();
int t = cmd.ExecuteNonQuery();
Conn.CloseConnection();
if (t > 0)
{
MessageBox.Show("Data Inserted Successfully!", "Success! Data Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Data is not Inserted! Try enter the data correctly", "Error! Data Not Inserted", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception msg)
{
MessageBox.Show(msg.Message);
}
}
public void Txt_AddUser_UserName_TextChanged(object sender, EventArgs e)
{
Query2 = "select * from Users_Table where User_Username='" + Txt_AddUser_UserName.Text + "'";
SqlDataAdapter QryCmd = new SqlDataAdapter(Query2, Conn.Connect);
DataTable dt = new DataTable();
QryCmd.Fill(dt);
if (dt.Rows.Count == 0)
{
PictureBox_Username_tick_cross.ImageLocation = @"C:\Users\faroo\OneDrive\Desktop\Graphin8-POS\Images\yes.png"; //Tick Image to show Username is Available
}
else
{
PictureBox_Username_tick_cross.ImageLocation = @"C:\Users\faroo\OneDrive\Desktop\Graphin8-POS\Images\no.png"; // Cross Image to Show Username already taken and is in the Database
}
}