Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi...Sir,

Plz solve my problem suppose I have a two table like a:- registration_mst and
login_mst. when I am new registering than it will successfully registered,
but how the email id and password and user type add into the login_mst table
after the registered .

please sir send me the asp.net with C# code for it with suitable example
Posted
Comments
CRDave1988 31-Jan-12 1:14am    
Can u show ur database structure and coding u have done so far?

That means you are inserting values into table "registration_mst" while registering.

Just after inserting the data into "registration_mst" table, again insert necessary data into table "login_mst" like below....

C#
string conStr = "your connection string";
SqlConnection con = new SqlConnection(conStr);
string sqlQuery = "INSERT INTO login_mst(email id, password, user type)values('" + txtEmail.Text + "','" + txtPassword.Text + "','" + ddlUserType.SelectedValue + "')";
SqlCommand cmd = new SqlCommand(sqlQuery, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();

(Here email and password comes from textboxes and usertype comes from one dropdown selection)
You can use the code and make necessary changes for your work....
 
Share this answer
 
Comments
Member 8588007 31-Jan-12 2:08am    
Thank you sir...
this code is ok...but i want to some different.this code manually insert data into the login_mst. I asked you when i registered than email id ,password,user type automatically will stored into the login_mst table when i click on the registration button at the registration time.
plz send me this type of code in asp.net C#..
Ok, I understand what you want. I will post the code after I implement the same... Wait for it....
Member 8588007 31-Jan-12 3:16am    
sir,, plz reply my answer of question eminently
Similar question asked:
See this answer by OriginalGriff[^]

Thanks
--RA
 
Share this answer
 
Create one store procedure as follows...

SQL
CREATE procedure proc_RegisterUser 
@firstName varchar(50),
@lastName varchar(50),
@DOB datetime,
@country int,
@state int,
@email_id varchar(80),
@mobile_no varchar(10),
@password varchar(30),
@userType varchar()
as
Begin Transaction

insert into registration_mst(firstName, lastName, DOB, country, state, mobile_no) 
values(@firstName, @lastName, @DOB, @country, @state, @mobile_no)

insert into login_mst(email_id, password, userType)values(@email_id, @password, @userType)

Commit Transaction


Then in code behind call this procedure and pass the parameters as follows....
C#
SqlConnection con = new SqlConnection(conStr);

//Calling the Procedure- proc_RegisterUser to insert the user
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.CommandText = "proc_RegisterUser";

// For table User_Details
cmd.Parameters.Add(new SqlParameter("@firstName", txtFirstName.Text));
cmd.Parameters.Add(new SqlParameter("@lastName", txtLastName.Text));
cmd.Parameters.Add(new SqlParameter("@DOB", txtDOB.Text));
cmd.Parameters.Add(new SqlParameter("@country", ddlCountry.SelectedValue));
cmd.Parameters.Add(new SqlParameter("@state", ddlState.SelectedValue));
cmd.Parameters.Add(new SqlParameter("@email_id", txtEmail.Text));
cmd.Parameters.Add(new SqlParameter("@MobileNo", txtMobile.Text));
cmd.Parameters.Add(new SqlParameter("@password", txtPassword.Text));
cmd.Parameters.Add(new SqlParameter("@userType",ddlUserType.SelectedValue));
con.Open();
cmd.ExecuteNonQuery();
con.Close();


Just follow the code and make necessary changes for table names, column names etc...
 
Share this answer
 
v2
Comments
Member 8588007 31-Jan-12 3:32am    
Thank you very much ...Sir....!
If this solution helped you, then accept the solution by clicking the button "Accept solution" and give some ratings, so that others would be able to know what exactly the solution is!!!!
Thanks,
Tadit
Member 8588007 31-Jan-12 10:25am    
sir...
how can create procedure. in which form..
plz tell me
To execute a procedure, just open sql server management studio and connect to the server giving your credentials. Then select the database you are working with. Click on "New query" and paste the sql procedure I provided, then click on execute (don't forget to make necessary changes to reflect your table and column structure).
If everything will be fine, then one message will come at bottom saying "Command(s) executed successfully.".
Then you can paste the coding I provided in .cs page to connect to execute the procedure and do the task.
(You can see the procedure by expanding
Your Database->Programmability->Stored Procedure).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900