Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 created date

Author  Topic 

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-15 : 04:31:49
Hi,
i have a question.
let say i register as a staff on today(15-9-2010), so in the created date column in database should display (15-9-2010).
means that when register complete, it should record the current date in database.
Besides that, also the last updated date.

thanks.

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-15 : 05:34:53
send the current date when register.. And also send updated time when making any actions ..
Maintain two columns in table as created and updated....
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-15 : 05:38:15
btnRegister.Attributes.Add("onClick", "javascript:alert('Your Register Successful!');");
Response.Redirect("Login.aspx");

What about this post ?
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-15 : 05:51:56
quote:
Originally posted by jafrywilson

btnRegister.Attributes.Add("onClick", "javascript:alert('Your Register Successful!');");
Response.Redirect("Login.aspx");

What about this post ?




This post is about after finish registration, i want show a message to user to let user know he/her successful register and redirect to login page.
when click register button, will validate success register or not,if not will state out the error otherwise will redirect to login page.
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-15 : 05:58:26
Then use if loop If(login==success)
{
go nex page
}
else
{
redirect
}
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-15 : 06:04:30
If you do like this
btnRegister.Attributes.Add("onClick", "javascript:alert('Your Register Successful!');");
Response.Redirect("Login.aspx");
After a successful registration it will redirect to login.aspx..
Use if loop for better design
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-17 : 00:26:10
quote:
Originally posted by jafrywilson

If you do like this
btnRegister.Attributes.Add("onClick", "javascript:alert('Your Register Successful!');");
Response.Redirect("Login.aspx");
After a successful registration it will redirect to login.aspx..
Use if loop for better design


Thanks For reply....
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-17 : 00:45:28
quote:
Originally posted by yvette

quote:
Originally posted by jafrywilson

If you do like this
btnRegister.Attributes.Add("onClick", "javascript:alert('Your Register Successful!');");
Response.Redirect("Login.aspx");
After a successful registration it will redirect to login.aspx..
Use if loop for better design


Thanks For reply....



Welcome
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-17 : 03:36:20
Hi,Jafrywilson

i have a question. where i want to put the if loop statement???coz i can't get what i expect...


my code:
protected void Page_Load(object sender, EventArgs e)
{

}


public string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["cwConnectionString1"].ConnectionString;
}


protected void LinkButton1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());
SqlCommand cmd;
SqlDataReader dr;
con.Open();
cmd = new SqlCommand("select [Username], [Password] from Employee where UserName='" + txtUserName + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
lblInfo.Text = "User Name already Exist!";
this.lblInfo.ForeColor = System.Drawing.Color.Red;
}
else
{
lblInfo.Text = "User Name is Available!";
}

}


protected void btnRegister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());

string sql = "INSERT INTO Employee (UserName, Password, LastName, FirstName, IdentityNo, Gender, Race, MaritalStatus, Religion, DOB, Address, PostalCode, City, State, Nationality, HomeTel, MobileNo, DriverLicenseNo, DriverLicenseExpiry, Position) VALUES " + " (@UserName, @Password, @LastName, @FirstName, @Identity, @Gender, @Race, @MaritalStatus, @Religion, @DOB, @Address, @PostalCode, @City, @State, @Nationality, @HomeTel, @MobileNo, @DriverLicenseNo, @DriverLicenseExpiry, @Position)";

try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;

string UserName = txtUserName.Text;
string Password = txtPassword.Text;
string LastName = txtLastName.Text;
string FirstName = txtLastName.Text;
string Identity = txtIdentity.Text;
string Gender = ddlGender.SelectedItem.Value;
string Race = ddlRace.SelectedItem.Value;
string MaritalStatus = ddlMarital.SelectedItem.Value;
string Religion = ddlReligion.SelectedItem.Value;
string DOB = txtDOB.Value;
string Address = txtAddress.Text;
string PostalCode = txtPoscode.Text;
string City = txtCity.Text;
string State = ddlState.SelectedItem.Value;
string Nationality = txtNationality.Text;
string HomeTel = txtHomeTel.Text;
string MobileNo = txtHPTel.Text;
string DriverLicenseNo = txtLicenseNo.Text;
string DriverLicenseExpiry = txtLicenseExpiry.Value;
string Position = ddlPosition.SelectedItem.Value;


cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Race", ddlRace.SelectedItem.Value);
cmd.Parameters.AddWithValue("@MaritalStatus", ddlMarital.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Religion", ddlReligion.SelectedItem.Value);
cmd.Parameters.AddWithValue("@DOB", Convert.ToDateTime(txtDOB.Value));
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@PostalCode", txtPoscode.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Nationality", txtNationality.Text);
cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text);
cmd.Parameters.AddWithValue("@MobileNo", txtHPTel.Text);
cmd.Parameters.AddWithValue("@DriverLicenseNo", txtLicenseNo.Text);
cmd.Parameters.AddWithValue("@DriverLicenseExpiry", Convert.ToDateTime(txtLicenseExpiry.Value));
cmd.Parameters.AddWithValue("@Position", ddlPosition.SelectedItem.Value);
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex_msg)
{
//Here will be catch elements
string msg = "Error occured while inserting";
msg += ex_msg.Message;
throw new Exception(msg);
}
finally
{
//Here will be fially elements
con.Close();
}
}
}


if (Register==success)
{
Response.redirect("Login.aspx");
}
else
{
Response.redirect("Register.aspx");
}
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-17 : 04:02:55



protected void Page_Load(object sender, EventArgs e)
{

}


public string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["cwConnectionString1"].ConnectionString;
}


protected int LinkButton1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());
SqlCommand cmd;
SqlDataReader dr;
con.Open();
cmd = new SqlCommand("select [Username], [Password] from Employee where UserName='" + txtUserName + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
lblInfo.Text = "User Name already Exist!";
this.lblInfo.ForeColor = System.Drawing.Color.Red;
}
else
{
lblInfo.Text = "User Name is Available!";
}

}


protected void btnRegister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());

string sql = "INSERT INTO Employee (UserName, Password, LastName, FirstName, IdentityNo, Gender, Race, MaritalStatus, Religion, DOB, Address, PostalCode, City, State, Nationality, HomeTel, MobileNo, DriverLicenseNo, DriverLicenseExpiry, Position) VALUES " + " (@UserName, @Password, @LastName, @FirstName, @Identity, @Gender, @Race, @MaritalStatus, @Religion, @DOB, @Address, @PostalCode, @City, @State, @Nationality, @HomeTel, @MobileNo, @DriverLicenseNo, @DriverLicenseExpiry, @Position)";

try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;

string UserName = txtUserName.Text;
string Password = txtPassword.Text;
string LastName = txtLastName.Text;
string FirstName = txtLastName.Text;
string Identity = txtIdentity.Text;
string Gender = ddlGender.SelectedItem.Value;
string Race = ddlRace.SelectedItem.Value;
string MaritalStatus = ddlMarital.SelectedItem.Value;
string Religion = ddlReligion.SelectedItem.Value;
string DOB = txtDOB.Value;
string Address = txtAddress.Text;
string PostalCode = txtPoscode.Text;
string City = txtCity.Text;
string State = ddlState.SelectedItem.Value;
string Nationality = txtNationality.Text;
string HomeTel = txtHomeTel.Text;
string MobileNo = txtHPTel.Text;
string DriverLicenseNo = txtLicenseNo.Text;
string DriverLicenseExpiry = txtLicenseExpiry.Value;
string Position = ddlPosition.SelectedItem.Value;


cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Race", ddlRace.SelectedItem.Value);
cmd.Parameters.AddWithValue("@MaritalStatus", ddlMarital.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Religion", ddlReligion.SelectedItem.Value);
cmd.Parameters.AddWithValue("@DOB", Convert.ToDateTime(txtDOB.Value));
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@PostalCode", txtPoscode.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Nationality", txtNationality.Text);
cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text);
cmd.Parameters.AddWithValue("@MobileNo", txtHPTel.Text);
cmd.Parameters.AddWithValue("@DriverLicenseNo", txtLicenseNo.Text);
cmd.Parameters.AddWithValue("@DriverLicenseExpiry", Convert.ToDateTime(txtLicenseExpiry.Value));
cmd.Parameters.AddWithValue("@Position", ddlPosition.SelectedItem.Value);
int s= cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex_msg)
{
//Here will be catch elements
string msg = "Error occured while inserting";
msg += ex_msg.Message;
throw new Exception(msg);
}
finally
{
//Here will be fially elements
con.Close();
}
return(s);
}
}


if (s==1)
{
Response.redirect("Login.aspx");
}
else
{
Response.redirect("Register.aspx");
}
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-17 : 04:05:53
Check about open and close braces...Insert this function if (s==1)
{
Response.redirect("Login.aspx");
}
else
{
Response.redirect("Register.aspx");
}

into btnRegister_Click
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-17 : 04:19:24
quote:
Originally posted by jafrywilson




protected void Page_Load(object sender, EventArgs e)
{

}


public string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["cwConnectionString1"].ConnectionString;
}


protected int LinkButton1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());
SqlCommand cmd;
SqlDataReader dr;
con.Open();
cmd = new SqlCommand("select [Username], [Password] from Employee where UserName='" + txtUserName + "'", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
lblInfo.Text = "User Name already Exist!";
this.lblInfo.ForeColor = System.Drawing.Color.Red;
}
else
{
lblInfo.Text = "User Name is Available!";
}

}


protected void btnRegister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());

string sql = "INSERT INTO Employee (UserName, Password, LastName, FirstName, IdentityNo, Gender, Race, MaritalStatus, Religion, DOB, Address, PostalCode, City, State, Nationality, HomeTel, MobileNo, DriverLicenseNo, DriverLicenseExpiry, Position) VALUES " + " (@UserName, @Password, @LastName, @FirstName, @Identity, @Gender, @Race, @MaritalStatus, @Religion, @DOB, @Address, @PostalCode, @City, @State, @Nationality, @HomeTel, @MobileNo, @DriverLicenseNo, @DriverLicenseExpiry, @Position)";

try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;

string UserName = txtUserName.Text;
string Password = txtPassword.Text;
string LastName = txtLastName.Text;
string FirstName = txtLastName.Text;
string Identity = txtIdentity.Text;
string Gender = ddlGender.SelectedItem.Value;
string Race = ddlRace.SelectedItem.Value;
string MaritalStatus = ddlMarital.SelectedItem.Value;
string Religion = ddlReligion.SelectedItem.Value;
string DOB = txtDOB.Value;
string Address = txtAddress.Text;
string PostalCode = txtPoscode.Text;
string City = txtCity.Text;
string State = ddlState.SelectedItem.Value;
string Nationality = txtNationality.Text;
string HomeTel = txtHomeTel.Text;
string MobileNo = txtHPTel.Text;
string DriverLicenseNo = txtLicenseNo.Text;
string DriverLicenseExpiry = txtLicenseExpiry.Value;
string Position = ddlPosition.SelectedItem.Value;


cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Race", ddlRace.SelectedItem.Value);
cmd.Parameters.AddWithValue("@MaritalStatus", ddlMarital.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Religion", ddlReligion.SelectedItem.Value);
cmd.Parameters.AddWithValue("@DOB", Convert.ToDateTime(txtDOB.Value));
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@PostalCode", txtPoscode.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Nationality", txtNationality.Text);
cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text);
cmd.Parameters.AddWithValue("@MobileNo", txtHPTel.Text);
cmd.Parameters.AddWithValue("@DriverLicenseNo", txtLicenseNo.Text);
cmd.Parameters.AddWithValue("@DriverLicenseExpiry", Convert.ToDateTime(txtLicenseExpiry.Value));
cmd.Parameters.AddWithValue("@Position", ddlPosition.SelectedItem.Value);
int s= cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex_msg)
{
//Here will be catch elements
string msg = "Error occured while inserting";
msg += ex_msg.Message;
throw new Exception(msg);
}
finally
{
//Here will be fially elements
con.Close();
}
return(s);
}
}


if (s==1)
{
Response.redirect("Login.aspx");
}
else
{
Response.redirect("Register.aspx");
}




The linkbutton_1 is for check availability of the username,
so can't change the void to int.
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-17 : 04:44:28
sorry ...convert btnRegister_Click to int..
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-17 : 04:46:31
quote:
Originally posted by jafrywilson

sorry ...convert btnRegister_Click to int..



never mind.i try 1st...
thanks..
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-17 : 04:52:04
ok..What about the output..
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-17 : 04:56:32
protected int btnRegister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());

string sql = "INSERT INTO Employee (UserName, Password, LastName, FirstName, IdentityNo, Gender, Race, MaritalStatus, Religion, DOB, Address, PostalCode, City, State, Nationality, HomeTel, MobileNo, DriverLicenseNo, DriverLicenseExpiry, Position) VALUES " + " (@UserName, @Password, @LastName, @FirstName, @Identity, @Gender, @Race, @MaritalStatus, @Religion, @DOB, @Address, @PostalCode, @City, @State, @Nationality, @HomeTel, @MobileNo, @DriverLicenseNo, @DriverLicenseExpiry, @Position)";

try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;


string UserName = txtUserName.Text;
string Password = txtPassword.Text;
string LastName = txtLastName.Text;
string FirstName = txtLastName.Text;
string Identity = txtIdentity.Text;
string Gender = ddlGender.SelectedItem.Value;
string Race = ddlRace.SelectedItem.Value;
string MaritalStatus = ddlMarital.SelectedItem.Value;
string Religion = ddlReligion.SelectedItem.Value;
string DOB = txtDOB.Value;
string Address = txtAddress.Text;
string PostalCode = txtPoscode.Text;
string City = txtCity.Text;
string State = ddlState.SelectedItem.Value;
string Nationality = txtNationality.Text;
string HomeTel = txtHomeTel.Text;
string MobileNo = txtHPTel.Text;
string DriverLicenseNo = txtLicenseNo.Text;
string DriverLicenseExpiry = txtLicenseExpiry.Value;
string Position = ddlPosition.SelectedItem.Value;


cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Race", ddlRace.SelectedItem.Value);
cmd.Parameters.AddWithValue("@MaritalStatus", ddlMarital.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Religion", ddlReligion.SelectedItem.Value);
cmd.Parameters.AddWithValue("@DOB", Convert.ToDateTime(txtDOB.Value));
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@PostalCode", txtPoscode.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Nationality", txtNationality.Text);
cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text);
cmd.Parameters.AddWithValue("@MobileNo", txtHPTel.Text);
cmd.Parameters.AddWithValue("@DriverLicenseNo", txtLicenseNo.Text);
cmd.Parameters.AddWithValue("@DriverLicenseExpiry", Convert.ToDateTime(txtLicenseExpiry.Value));
cmd.Parameters.AddWithValue("@Position", ddlPosition.SelectedItem.Value);
int s = cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex_msg)
{
//Here will be catch elements
string msg = "Error occured while inserting";
msg += ex_msg.Message;
throw new Exception(msg);
}
finally
{
//Here will be fially elements
con.Close();
}
return (s)
{
if (s==1)
{
Response.Redirect("Login.aspx");
}
else
{
Response.Redirect("Register.aspx");
}
}
}


}
that is the code i try, and error i get:
Error 1 ; expected
Error 2 'int Register.btnRegister_Click(object, System.EventArgs)' has the wrong return type

Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-17 : 05:01:13
return s;

if (s==1)
{
Response.Redirect("Login.aspx");
}
else
{
Response.Redirect("Register.aspx");
}

}
Try this..
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-17 : 05:04:02
protected int btnRegister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());

string sql = "INSERT INTO Employee (UserName, Password, LastName, FirstName, IdentityNo, Gender, Race, MaritalStatus, Religion, DOB, Address, PostalCode, City, State, Nationality, HomeTel, MobileNo, DriverLicenseNo, DriverLicenseExpiry, Position) VALUES " + " (@UserName, @Password, @LastName, @FirstName, @Identity, @Gender, @Race, @MaritalStatus, @Religion, @DOB, @Address, @PostalCode, @City, @State, @Nationality, @HomeTel, @MobileNo, @DriverLicenseNo, @DriverLicenseExpiry, @Position)";

try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;


string UserName = txtUserName.Text;
string Password = txtPassword.Text;
string LastName = txtLastName.Text;
string FirstName = txtLastName.Text;
string Identity = txtIdentity.Text;
string Gender = ddlGender.SelectedItem.Value;
string Race = ddlRace.SelectedItem.Value;
string MaritalStatus = ddlMarital.SelectedItem.Value;
string Religion = ddlReligion.SelectedItem.Value;
string DOB = txtDOB.Value;
string Address = txtAddress.Text;
string PostalCode = txtPoscode.Text;
string City = txtCity.Text;
string State = ddlState.SelectedItem.Value;
string Nationality = txtNationality.Text;
string HomeTel = txtHomeTel.Text;
string MobileNo = txtHPTel.Text;
string DriverLicenseNo = txtLicenseNo.Text;
string DriverLicenseExpiry = txtLicenseExpiry.Value;
string Position = ddlPosition.SelectedItem.Value;


cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Race", ddlRace.SelectedItem.Value);
cmd.Parameters.AddWithValue("@MaritalStatus", ddlMarital.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Religion", ddlReligion.SelectedItem.Value);
cmd.Parameters.AddWithValue("@DOB", Convert.ToDateTime(txtDOB.Value));
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@PostalCode", txtPoscode.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Nationality", txtNationality.Text);
cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text);
cmd.Parameters.AddWithValue("@MobileNo", txtHPTel.Text);
cmd.Parameters.AddWithValue("@DriverLicenseNo", txtLicenseNo.Text);
cmd.Parameters.AddWithValue("@DriverLicenseExpiry", Convert.ToDateTime(txtLicenseExpiry.Value));
cmd.Parameters.AddWithValue("@Position", ddlPosition.SelectedItem.Value);
int s = cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex_msg)
{
//Here will be catch elements
string msg = "Error occured while inserting";
msg += ex_msg.Message;
throw new Exception(msg);
}
finally
{
//Here will be fially elements
con.Close();
}
return s;

if (s==1)
{
Response.Redirect("Login.aspx");
}
else
{
Response.Redirect("Register.aspx");
}

}
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-17 : 05:08:36
quote:
Originally posted by jafrywilson

return s;

if (s==1)
{
Response.Redirect("Login.aspx");
}
else
{
Response.Redirect("Register.aspx");
}

}
Try this..




still have error:

Error 1 The name 's' does not exist in the current context
Error 2 The name 's' does not exist in the current context
Error 3 'int Register.btnRegister_Click(object, System.EventArgs)' has the wrong return type
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-17 : 05:11:05
protected void btnRegister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());

string sql = "INSERT INTO Employee (UserName, Password, LastName, FirstName, IdentityNo, Gender, Race, MaritalStatus, Religion, DOB, Address, PostalCode, City, State, Nationality, HomeTel, MobileNo, DriverLicenseNo, DriverLicenseExpiry, Position) VALUES " + " (@UserName, @Password, @LastName, @FirstName, @Identity, @Gender, @Race, @MaritalStatus, @Religion, @DOB, @Address, @PostalCode, @City, @State, @Nationality, @HomeTel, @MobileNo, @DriverLicenseNo, @DriverLicenseExpiry, @Position)";

try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;


string UserName = txtUserName.Text;
string Password = txtPassword.Text;
string LastName = txtLastName.Text;
string FirstName = txtLastName.Text;
string Identity = txtIdentity.Text;
string Gender = ddlGender.SelectedItem.Value;
string Race = ddlRace.SelectedItem.Value;
string MaritalStatus = ddlMarital.SelectedItem.Value;
string Religion = ddlReligion.SelectedItem.Value;
string DOB = txtDOB.Value;
string Address = txtAddress.Text;
string PostalCode = txtPoscode.Text;
string City = txtCity.Text;
string State = ddlState.SelectedItem.Value;
string Nationality = txtNationality.Text;
string HomeTel = txtHomeTel.Text;
string MobileNo = txtHPTel.Text;
string DriverLicenseNo = txtLicenseNo.Text;
string DriverLicenseExpiry = txtLicenseExpiry.Value;
string Position = ddlPosition.SelectedItem.Value;


cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Race", ddlRace.SelectedItem.Value);
cmd.Parameters.AddWithValue("@MaritalStatus", ddlMarital.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Religion", ddlReligion.SelectedItem.Value);
cmd.Parameters.AddWithValue("@DOB", Convert.ToDateTime(txtDOB.Value));
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@PostalCode", txtPoscode.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Nationality", txtNationality.Text);
cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text);
cmd.Parameters.AddWithValue("@MobileNo", txtHPTel.Text);
cmd.Parameters.AddWithValue("@DriverLicenseNo", txtLicenseNo.Text);
cmd.Parameters.AddWithValue("@DriverLicenseExpiry", Convert.ToDateTime(txtLicenseExpiry.Value));
cmd.Parameters.AddWithValue("@Position", ddlPosition.SelectedItem.Value);
int s = cmd.ExecuteNonQuery();
if (s==1)
{
Response.Redirect("Login.aspx");
}
else
{
Response.Redirect("Register.aspx");
}

}
catch (System.Data.SqlClient.SqlException ex_msg)
{
//Here will be catch elements
string msg = "Error occured while inserting";
msg += ex_msg.Message;
throw new Exception(msg);
}
finally
{
//Here will be fially elements
con.Close();
}

}
Go to Top of Page

yvette
Yak Posting Veteran

74 Posts

Posted - 2010-09-17 : 05:18:39
quote:
Originally posted by jafrywilson

protected void btnRegister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(GetConnectionString());

string sql = "INSERT INTO Employee (UserName, Password, LastName, FirstName, IdentityNo, Gender, Race, MaritalStatus, Religion, DOB, Address, PostalCode, City, State, Nationality, HomeTel, MobileNo, DriverLicenseNo, DriverLicenseExpiry, Position) VALUES " + " (@UserName, @Password, @LastName, @FirstName, @Identity, @Gender, @Race, @MaritalStatus, @Religion, @DOB, @Address, @PostalCode, @City, @State, @Nationality, @HomeTel, @MobileNo, @DriverLicenseNo, @DriverLicenseExpiry, @Position)";

try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;


string UserName = txtUserName.Text;
string Password = txtPassword.Text;
string LastName = txtLastName.Text;
string FirstName = txtLastName.Text;
string Identity = txtIdentity.Text;
string Gender = ddlGender.SelectedItem.Value;
string Race = ddlRace.SelectedItem.Value;
string MaritalStatus = ddlMarital.SelectedItem.Value;
string Religion = ddlReligion.SelectedItem.Value;
string DOB = txtDOB.Value;
string Address = txtAddress.Text;
string PostalCode = txtPoscode.Text;
string City = txtCity.Text;
string State = ddlState.SelectedItem.Value;
string Nationality = txtNationality.Text;
string HomeTel = txtHomeTel.Text;
string MobileNo = txtHPTel.Text;
string DriverLicenseNo = txtLicenseNo.Text;
string DriverLicenseExpiry = txtLicenseExpiry.Value;
string Position = ddlPosition.SelectedItem.Value;


cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Identity", txtIdentity.Text);
cmd.Parameters.AddWithValue("@Gender", ddlGender.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Race", ddlRace.SelectedItem.Value);
cmd.Parameters.AddWithValue("@MaritalStatus", ddlMarital.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Religion", ddlReligion.SelectedItem.Value);
cmd.Parameters.AddWithValue("@DOB", Convert.ToDateTime(txtDOB.Value));
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@PostalCode", txtPoscode.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Value);
cmd.Parameters.AddWithValue("@Nationality", txtNationality.Text);
cmd.Parameters.AddWithValue("@HomeTel", txtHomeTel.Text);
cmd.Parameters.AddWithValue("@MobileNo", txtHPTel.Text);
cmd.Parameters.AddWithValue("@DriverLicenseNo", txtLicenseNo.Text);
cmd.Parameters.AddWithValue("@DriverLicenseExpiry", Convert.ToDateTime(txtLicenseExpiry.Value));
cmd.Parameters.AddWithValue("@Position", ddlPosition.SelectedItem.Value);
int s = cmd.ExecuteNonQuery();
if (s==1)
{
Response.Redirect("Login.aspx");
}
else
{
Response.Redirect("Register.aspx");
}

}
catch (System.Data.SqlClient.SqlException ex_msg)
{
//Here will be catch elements
string msg = "Error occured while inserting";
msg += ex_msg.Message;
throw new Exception(msg);
}
finally
{
//Here will be fially elements
con.Close();
}

}




Thanks...This code works,but it cause that i can have the same username, password even all the details of the employee...
Go to Top of Page
    Next Page

- Advertisement -