Finish Button Click

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 3333 Views - Last Post: 02 September 2009 - 07:56 AM Rate Topic: -----

#1 deleon_chesterhomer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 184
  • Joined: 08-September 07

Finish Button Click

Posted 31 August 2009 - 02:48 AM

i wanted to open another page when inserting of data is succesffully done..otherwise a page that will redirect the user to fill up again the registration to correct their mistakes..can you give me some info how to do that??


here's my code in aspx.cs

 protected void Wizard1_FinishButtonclick(object sender, WizardNavigationEventArgs e)
	{
		insertDataIntoDB(txtFirstName.Text.ToString().Trim(),   txtMiddleName.Text.ToString().Trim(), txtLastName.Text.ToString().Trim(), 

	}




Is This A Good Question/Topic? 0
  • +

Replies To: Finish Button Click

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Finish Button Click

Posted 31 August 2009 - 03:34 AM

try to use Response.Redirect();
quick example:
Response.Redirect("http://www.dreamincode.net/");

Was This Post Helpful? 1
  • +
  • -

#3 deleon_chesterhomer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 184
  • Joined: 08-September 07

Re: Finish Button Click

Posted 31 August 2009 - 06:43 AM

yeah u got it right.. but i have a table named register_db and it contains fieldnames and my primary key is the email_address field..

can you help me figure it out, i just want it to be checked if the emailadress is not existing it will be redirected to another page and if not it will just come back to the same page..


i don't know how to put it in aspx.cs code in the same area(protected void Wizard1_FinishButtonclick(object sender, WizardNavigationEventArgs e))
hope you can help me again..:)
Was This Post Helpful? 0
  • +
  • -

#4 W3bDev  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • Posts: 379
  • Joined: 15-March 09

Re: Finish Button Click

Posted 31 August 2009 - 06:50 AM

Deleon,

Do a SQL SELECT to the table in question. If it has a returned result, then throw an error and return to the same page, if not, redirect to the confirmation page.
Was This Post Helpful? 0
  • +
  • -

#5 deleon_chesterhomer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 184
  • Joined: 08-September 07

Re: Finish Button Click

Posted 31 August 2009 - 06:56 AM

webdev,

this is the query i have, i am a begginer, i don't know how to use functions from this aspx.cs ...thanks:)

[code]

SELECT email FROM Register_db

[code]
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Finish Button Click

Posted 31 August 2009 - 07:12 AM

this sql will probably work better...

SELECT 
     COUNT(*) 
FROM Register_db WHERE Email = @EmailAddress


and you will pass in the email address.

if it returns 0, then the email is not registered
Was This Post Helpful? 1
  • +
  • -

#8 deleon_chesterhomer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 184
  • Joined: 08-September 07

Re: Finish Button Click

Posted 31 August 2009 - 07:16 AM

View Posteclipsed4utoo, on 31 Aug, 2009 - 06:12 AM, said:

this sql will probably work better...

SELECT 
     COUNT(*) 
FROM Register_db WHERE Email = @EmailAddress


and you will pass in the email address.

if it returns 0, then the email is not registered



oh yeah that's probably the best statement but..i still don't know how to code it beyond the public void WIzard1Finishbuttonclick can you help to do that?
Was This Post Helpful? 0
  • +
  • -

#9 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 285
  • View blog
  • Posts: 1,503
  • Joined: 07-April 08

Re: Finish Button Click

Posted 31 August 2009 - 07:31 AM

Not to sound rude, but google is your friend mate. You need to find some good tutorials that will help you out.

like the following:

SQLConnection

here is a good google search to get you started:

Google search for ADO.NET
Was This Post Helpful? 0
  • +
  • -

#10 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Finish Button Click

Posted 31 August 2009 - 07:51 AM

look up using the SqlConnection, SqlCommand, and the ExecuteScalar() command of the SqlCommand class.

this will also be a parameterized query, so that's something else for you to look up.
Was This Post Helpful? 0
  • +
  • -

#11 deleon_chesterhomer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 184
  • Joined: 08-September 07

Re: Finish Button Click

Posted 31 August 2009 - 08:21 AM

View Posteclipsed4utoo, on 31 Aug, 2009 - 06:51 AM, said:

look up using the SqlConnection, SqlCommand, and the ExecuteScalar() command of the SqlCommand class.

this will also be a parameterized query, so that's something else for you to look up.


hello :) :) here's my created code.. it has still bugs in it..
 protected void Wizard1_FinishButtonclick(object sender, WizardNavigationEventArgs e)
	{
		insertDataIntoDB(txtEmail.Text.ToString().Trim());
	 


		// create a command object
		//i dont know if this is correct because i don't know how to do it 



					SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=FormWizard_df;Integrated Security=SSPI");

		//my sql command
		//it has an error
		SqlCommand cmd = new SqlCommand("SELECT Email FROM Register_db, conn);

			if (@Email = 0)
			{
				//another page will load which is the confirmation you successfully done;
			}
			else
			{
				//back to the page
			}
		


	}


Was This Post Helpful? 0
  • +
  • -

#12 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Finish Button Click

Posted 31 August 2009 - 08:47 AM

you need to close the quotation.

SqlCommand cmd = new SqlCommand("SELECT Email FROM Register_db", conn);



that will fix your issue. To actually have the code do what you want...

insertDataIntoDB(txtEmail.Text.ToString().Trim());

using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=FormWizard_df;Integrated Security=SSPI"))
{
      using (SqlCommand cmd = conn.CreateCommand())
      {
            cmd.CommandText = "SELECT COUNT(*) FROM Register_db WHERE Email = @EmailAddress";
            conn.Open();
            cmd.Parameters.AddWithValue("@EmailAddress", txtEmail.Text.Trim());

            int number = (int)cmd.ExecuteScalar();

            if (number == 0)
            {
                   // not registered
                   return;
            }

            Response.Redirect(somePageForConfirmation);
      }
}



that should work for you. if you get an error, please post the actual error and the line of code that is causing the error.
Was This Post Helpful? 0
  • +
  • -

#13 deleon_chesterhomer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 184
  • Joined: 08-September 07

Re: Finish Button Click

Posted 01 September 2009 - 07:08 AM

View Posteclipsed4utoo, on 31 Aug, 2009 - 07:47 AM, said:

you need to close the quotation.

SqlCommand cmd = new SqlCommand("SELECT Email FROM Register_db", conn);



that will fix your issue. To actually have the code do what you want...

insertDataIntoDB(txtEmail.Text.ToString().Trim());

using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=FormWizard_df;Integrated Security=SSPI"))
{
      using (SqlCommand cmd = conn.CreateCommand())
      {
            cmd.CommandText = "SELECT COUNT(*) FROM Register_db WHERE Email = @EmailAddress";
            conn.Open();
            cmd.Parameters.AddWithValue("@EmailAddress", txtEmail.Text.Trim());

            int number = (int)cmd.ExecuteScalar();

            if (number == 0)
            {
                   // not registered
                   return;
            }

            Response.Redirect(somePageForConfirmation);
      }
}



that should work for you. if you get an error, please post the actual error and the line of code that is causing the error.


thanks again..
but there's an error

1.)The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)
using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=FormWizard_db.mdf;Integrated Security=SSPI"))



2.)Embedded statement cannot be a declaration or labeled statement
 SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM Register_db WHERE Email = @EmailAddress", conn);

3.)A local variable named 'cmd' cannot be declared in this scope because it would give a different meaning to 'cmd', which is already used in a 'parent or current' scope to denote something else	

[code]
using (SqlCommand cmd = conn.CreateCommand())  




here's my actual code in aspx.cs


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}

	public void insertDataIntoDB(string FirstName, string MiddleName, string LastName, string Address, string Province, string ContactNum,string Email, string Password)
	{

		string conn = System.Configuration.ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString;
		System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(conn);
		string MySQL = "StoredProcedure1";
		System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(MySQL, myConnection);
		cmd.CommandType = System.Data.CommandType.StoredProcedure;
		cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FirstName", FirstName));
		cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MiddleName",MiddleName));
		cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@LastName", LastName));
		cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", Address));
		cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Province", Province));
		cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactNum", ContactNum));
		cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Email", Email));
		cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Password", Password));
	   

		myConnection.Open();
		cmd.ExecuteNonQuery();
		myConnection.Close();

	}
	protected void Wizard1_FinishButtonclick(object sender, WizardNavigationEventArgs e)
	{
	   
	   

		insertDataIntoDB(txtFirstName.Text.ToString().Trim(), txtMiddleName.Text.ToString().Trim(), txtLastName.Text.ToString().Trim(), txtAddress.Text.ToString().Trim(), DDLB_Province.SelectedItem.Value.ToString().Trim(), txtContactNum.Text.ToString().Trim(), txtEmail.Text.ToString().Trim(), txtPassword.Text.ToString().Trim());
		using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=FormWizard_db.mdf;Integrated Security=SSPI")) 
	  //  Response.Redirect("http://localhost:2440/FormWizard/Main.aspx");


	   SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM Register_db WHERE Email = @EmailAddress", conn);
	   {	  
		   using (SqlCommand cmd = conn.CreateCommand())	
		   {			cmd.CommandText = "SELECT COUNT(*) FROM Register_db WHERE Email = @EmailAddress";	 
						conn.Open();	  
						cmd.Parameters.AddWithValue("@EmailAddress", txtEmail.Text.Trim());		 
						int number = (int)cmd.ExecuteScalar();			
			if (number == 0)		  
						{	  
							// not registered		
							return;		
						}		  
						   // Response.Redirect(somePageForConfirmation);   
		   }
	   }
		


	}
}





:D hope ypu can help me sort it out.. :)
Was This Post Helpful? 0
  • +
  • -

#14 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 285
  • View blog
  • Posts: 1,503
  • Joined: 07-April 08

Re: Finish Button Click

Posted 01 September 2009 - 07:24 AM

you are getting that error because you do not have the using directive to tell the compiler where to find SQLConnection

you need to have using System.Data.SqlClient;

This post has been edited by rgfirefly24: 01 September 2009 - 07:25 AM

Was This Post Helpful? 1
  • +
  • -

#15 deleon_chesterhomer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 184
  • Joined: 08-September 07

Re: Finish Button Click

Posted 01 September 2009 - 07:55 AM

View Postrgfirefly24, on 1 Sep, 2009 - 06:24 AM, said:

you are getting that error because you do not have the using directive to tell the compiler where to find SQLConnection

you need to have using System.Data.SqlClient;



okay thanks..some of the errors are gone,

this is the code that i really don't know how to format

using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=FormWizard_db.mdf;Integrated Security=SSPI")) 


it has an error saying ==The name 'conn' does not exist in the current context
Was This Post Helpful? 0
  • +
  • -

#16 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Finish Button Click

Posted 01 September 2009 - 08:14 AM

View Postdeleon_chesterhomer, on 1 Sep, 2009 - 10:55 AM, said:

View Postrgfirefly24, on 1 Sep, 2009 - 06:24 AM, said:

you are getting that error because you do not have the using directive to tell the compiler where to find SQLConnection

you need to have using System.Data.SqlClient;



okay thanks..some of the errors are gone,

this is the code that i really don't know how to format

using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=FormWizard_db.mdf;Integrated Security=SSPI")) 


it has an error saying ==The name 'conn' does not exist in the current context


The code that I posted should have been all of the code in the button click event. You copied and paste it into different parts and left your original code. Copy the code that I posted, and overwrite everything in your "Wizard1_FinishButtonclick" event. Then try it.

and this is how you format the "using" block...

http://msdn.microsof...y/yh598w02.aspx
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2