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 KandasamyRank #2,151 · 661 reputationPosted Apr 10, 2009, 4:39 AM EDT
Try the following
add the following code in MouseDoubleClick event of datagridview..
} when a user double click a row... its just retriew its 1st cell [username] and send it to form2 via constructor add the following code in form2 // its a constructor public form2(String usr) { InitializeComponent(); textBox1.Text=usr; } this will store passed value into textbox.. try it..Vimal KandasamyRank #2,151 · 661 reputationPosted Apr 9, 2009, 11:00 PM EDT
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();
}
sachi vasishta180 reputationPosted Apr 9, 2009, 11:53 PM EDT
the textBox3.Focus(); is not working ,I mean the indifferent data(pass and con pass) are still being inserted into the database
Vimal KandasamyRank #2,151 · 661 reputationPosted Apr 10, 2009, 12:10 AM EDT
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 vasishta180 reputationPosted Apr 10, 2009, 12:34 AM EDT
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 KandasamyRank #2,151 · 661 reputationPosted Apr 10, 2009, 1:13 AM EDT
This is right structure
sachi vasishta180 reputationPosted Apr 10, 2009, 2:20 AM EDT
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
sachi vasishta180 reputationPosted Apr 10, 2009, 10:12 PM EDT
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.
Vimal KandasamyRank #2,151 · 661 reputationPosted Apr 10, 2009, 10:56 PM EDT
try this,