我无法将主键值从一个表单传递给其他表单,我不使用gridview
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();
string id = HF_Reg_Id.Value.ToString();
Response.Redirect("VanRegister.aspx?id= "+id);
}
我有2个表DriverRegistration
和VanRegistration
。当司机填写驾驶员登记表并提交时,将打开面包车登记表,并在VanRegistration
表DriverReg_id
中插入。这就是为什么我想通过查询字符串传递DriverReg_id
。
DriverRegistration
表
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
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
答案 0 :(得分:-1)
我认为,您使用Session["ID"]=HF_Reg_Id.Value.ToString();
并重定向到VanRegister.aspx,然后检查if(Session["ID"]!=null)
继续。祝你好运。