TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sundas Ali
NA
7
7k
call one column in other table
Jul 31 2016 3:44 AM
i have 2 tables one is Driver Registration and second is Van Registration
Van Register Table:
there is two form when driver register successfully then Van register form open, so i want to a driver id in van table
Insertion Procedure of Driver
ALTER PROC [dbo].[SP_INSERT_DriverRegistration]
@DriverReg_id as int,
@Fname varchar(50),
@Lname varchar(50),
@Email varchar(50),
@Password varchar(50),
@Gender varchar(50),
@Mobile varchar(50),
@CNIC varchar(50),
@Address varchar(50),
@DrivingExperience varchar(50),
@license varchar(50),
@Route varchar(50)
As
BEGIN
IF @DriverReg_id =-1 --FOR INSERTION IF CONDITION TRUE
if exists(select top 1 DriverReg_id from DriverRegistration where Fname=@Fname and Mobile=@Mobile)
begin
select -1
end
else begin
INSERT INTO DriverRegistration(
Fname
,Lname
,Email
,Password
,Gender
,Mobile
,CNIC
,Address
,DrivingExperience
,license
,Route
,CreatedOn
,CreatedBy
,UpdatedBy
,UpdatedOn
,IsActive
,IsVerified )
values(
@Fname
,@Lname
,@Email
,@Password
,@Gender
,@Mobile
,@CNIC
,@Address
,@DrivingExperience
,@license
,@Route
,GETDATE()
,1
,null
,null
,1
,0
)
select SCOPE_IDENTITY()
End
ELSE BEGIN
UPDATE DriverRegistration
SET
Fname=@Fname
,Lname=@Lname
,Email=@Email
,Password=@Password
,Gender=@Gender
,Mobile=@Mobile
,CNIC=@CNIC
,Address=@Address
,DrivingExperience=@DrivingExperience
,license=@license
,Route=@Route
,UpdatedOn=GETDATE()
,UpdatedBy=1
WHERE DriverReg_id=@DriverReg_id
END
END
public partial class VanRegister : System.Web.UI.Page
{
string conString = System.Configuration.ConfigurationManager.ConnectionStrings["myConstring"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.Count > 0)
{
HF_DriverReg_id.Value = Request.QueryString["DriverReg_id"].ToString();
}
}
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand("SP_INSERT_VanRegistration", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@VanReg_id", HF_Van_Id.Value);
cmd.Parameters.Add("@DriverReg_id", HF_DriverReg_id.Value);
cmd.Parameters.Add("@VehicleNumber", VehicleNumber.Text);
cmd.Parameters.Add("@VehicleModel", VehicleModel.Text);
cmd.Parameters.Add("@VehicleType", VehicleType.Text);
cmd.Parameters.Add("@SeatsNumbers", SeatsNumbers.Text);
cmd.Parameters.Add("@VehicleImage", VehicleImage);
cmd.Parameters.Add("@EmpImgPath", "EmpImages/" + VehicleImage);
con.Open();
string result = cmd.ExecuteNonQuery().ToString();
con.Close();
con.Dispose();
int num = int.Parse(result);
if (result == "1")
{
lblMsg.Text = "Registered successfully we will send you a confirmation email soon";
}
else
{
lblMsg.Text = "Alreday exixts";
}
same for Driver
protected void btnRegister_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand("SP_INSERT_DriverRegistration", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@DriverReg_id", HF_Reg_Id.Value);
cmd.Parameters.Add("@Fname", Fname.Text);
cmd.Parameters.Add("@Lname", Lname.Text);
cmd.Parameters.Add("@Email", Email1.Text);
cmd.Parameters.Add("@Password", Password.Text);
cmd.Parameters.Add("@Gender", Gender.Text);
cmd.Parameters.Add("@Mobile", Mobile.Text);
cmd.Parameters.Add("@CNIC", CNIC.Text);
cmd.Parameters.Add("@Address", Address.Text);
cmd.Parameters.Add("@DrivingExperience", DrivingExperience.Text);
cmd.Parameters.Add("@license", license.Text);
cmd.Parameters.Add("@Route", ddlRoute.SelectedItem.Text);
con.Open();
string result = cmd.ExecuteNonQuery().ToString();
con.Close();
int num = int.Parse(result);
// if (result == "1")
if (num > 1)
{
//lblMsg.Text = "registered successfully we will send you a confirmation email soon";
Response.Redirect("VanRegister.aspx");
}
else
{
//lblMsg.Text = "Alreday exixts";
Response.Redirect("VanRegister.aspx");
}
Reply
Answers (
2
)
insert data from checked List Box to sql server database
How can I Add dynamic stored procedure in c#