Hi,
I have a winform which contains three text boxes and a button. The textboxes are username,password and confirm password. I have entered the values for the three text boxes and clicked the ok button but it is not properly validating
under button1_click method I have the following code
string uname=textBox1.Text.ToString();
string pass=textBox2.Text.Tostring();
string confirm=textBox3.Text.ToString();
if(pass!=confirm)
MessageBox.Show("Please retype password");
here if I input different values for pass and confirm it is just displaying the message in messagebox but not prompting me back to the textBox3 and also that diffrent values are being inserted into the database. How to avoid this??
Vimal KandasamyPosted Apr 10, 2009, 8:39 AM
Try the following
add the following code in MouseDoubleClick event of datagridview..
{Vimal KandasamyPosted Apr 11, 2009, 2:56 AM
try this,
sachi vasishtaPosted Apr 11, 2009, 2:12 AM
Hi,
Vimal I have a winform namely form1 which contains two radio buttons gotoform2 and gotoform3. Now if I click on the gotoform2 radiobutton then it should close the form1 and open the new winform form2.In form2 I have a button called `back` whick on clicking should reopen the winform form1. In button1_click method of form2 I have written the following code
Form1.ActiveForm.Show();
but if I click on `back` button no action is performed.
sachi vasishtaPosted Apr 10, 2009, 6:20 AM
Thanks brother,you helped me a lot.
vimal now I am having trouble with datagridview control. I think you have understood the code that i have sent. Now what I need is I will retrive the info from a table(containing fields username,password,etc)and display it on the datagridview.Now if i click on a particular row then it should take me into the new winform and should display the username of the selected row of first form into the textbox of new winform. I did search in the google, and other forums but didn't get any solution.Plz help
Thanks
Vimal KandasamyPosted Apr 10, 2009, 5:13 AM
This is right structure
{{{string qry = string.Format("insert into employee(username,password,emp_type) values('{0}','{1}','{2}')", uname, paswd, utype);sachi vasishtaPosted Apr 10, 2009, 4:34 AM
here is the code
private void button1_Click(object sender, EventArgs e){
string uname = textBox1.Text.ToString(); string paswd = textBox2.Text.ToString(); string confpasswd = textBox5.Text.ToString(); if (paswd != confpasswd){
MessageBox.Show(" Invalid password Please retype");textBox5.Focus();
}
string fname = textBox6.Text.ToString(); string lname = textBox7.Text.ToString(); string utype = comboBox1.SelectedItem.ToString();
string qry = string.Format("insert into employee(username,password,emp_type) values('{0}','{1}','{2}')", uname, paswd, utype); OdbcConnection oConnection = new OdbcConnection("Dsn=Medoffice"); /* connection for 'employee' table */oConnection.Open();
OdbcCommand oCommand = new OdbcCommand(qry);oCommand.Connection = oConnection;
oCommand.ExecuteNonQuery();
oConnection.Close();
string qry1 = string.Format("insert into usersprofile(userid,firstname,lastname)values('{0}','{1}','{2}')",utype,fname,lname); OdbcConnection oConnection1 = new OdbcConnection("Dsn=Medoffice"); /* connection for 'usersprofile' table */oConnection1.Open();
OdbcCommand oCommand1 = new OdbcCommand(qry1);oCommand1.Connection = oConnection1;
oCommand1.ExecuteNonQuery();
oConnection1.Close();
if (utype == "Reception") MessageBox.Show(" New Reception created"); else if (utype == "Doctor") MessageBox.Show(" New Doctor created"); else MessageBox.Show(" New Administrator created"); Form8.ActiveForm.Close();}
Vimal KandasamyPosted Apr 10, 2009, 4:10 AM
in your code, where you insert your values into database?... whether its in button1_click method or some in other method?..
you have to ensure that your insert code [insert value into database] will be executed after all inputs are correct...if they are not correct you have to show error msg.
sachi vasishtaPosted Apr 10, 2009, 3:53 AM
the textBox3.Focus(); is not working ,I mean the indifferent data(pass and con pass) are still being inserted into the database
Vimal KandasamyPosted Apr 10, 2009, 3:00 AM
you have to re arrange conditions..
like below
string uname=textBox1.Text.ToString();
string pass=textBox2.Text.Tostring();
string confirm=textBox3.Text.ToString();
if(pass==confirm)
{
//your code to add inputs to database
}
else
{
MessageBox.Show("Please retype password");
textbox3.Focus();
}