0

私は登録フォームを持っており、その後、ユーザーIDに基づいて最初のページに必須フィールドを挿入しています。下の2ページ目の詳細を更新しています。これが私のコードです。

ALTER procedure [dbo].[Insertreg]

( @id int output,@FirstName varchar (50),@LastName varchar(50) ,@Dob datetime,
        @Gender varchar(20) ,@MobileNo nchar(10) ,@Country varchar(50) ,
    @State varchar (50),@EmailId varchar (50),@Password nchar (15)

)
as
begin
insert into Profile_Master(FirstName,LastName,Dob,Gender,MobileNo,Country,State,EmailId,Password)
 values
(@FirstName,@LastName,@Dob,@Gender,@MobileNo,@Country,@State,@EmailId,@Password)
set @id=SCOPE_IDENTITY()
end


    ALTER procedure [dbo].[sp_update]

(@id int output,@FormFiledBy varchar (50),@MaritalStatus varchar (50),@Height varchar (50),
@Religion varchar (50),@Caste varchar (100),
 @MotherTongue varchar(50),@Education varchar (100),@Occupation varchar(50),
 @CountryofResidence varchar (50),@EducationDetails varchar (100),@AnnualIncome varchar(50),
@CountryOfBirth varchar(50),@BirthPlace varchar(50),@TimeOfBirth nchar(10),@StarSign varchar (100),
@Gothram varchar (50),@Rassi varchar(50),@HavinChildren varchar(10),@PhysicalStatus varchar (100))

as
begin

update Profile_Master
 set FormFiledBy=@FormFiledBy,MaritalStatus=@MaritalStatus,Height=@Height,
Religion=@Religion,Caste=@Caste,MotherTongue=@MotherTongue,
Education=@Education,Occupation=@Occupation,CountryofResidence=@CountryofResidence,EducationDetails=@EducationDetails,
AnnualIncome=@AnnualIncome,CountryOfBirth=@CountryOfBirth,BirthPlace=@BirthPlace,TimeOfBirth=@TimeOfBirth,
StarSign=@StarSign,Gothram=@Gothram,Rassi=@Rassi,HavinChildren=@HavinChildren,PhysicalStatus=@PhysicalStatus

where UserId=@id
end

protected void Button1_Click(object sender, EventArgs e)
    {
        // Get User ID from DAL
        int chk = 0;
        if (Session["EmailID"] != null)
        {
            emailID = Session["EmailID"].ToString();
        }
        ProfileMasterBLL prfbll =new ProfileMasterBLL();
        prfbll.EmailID = emailID;
        string userid = ProfileMasterDAL.GetUserIdByEmailID(emailID);

        // Capture remaining parameters
        if (userid != null)
        {

            prfbll.FormFiledBy = RadioButtonList1.SelectedItem.Text;
            prfbll.MaritalStatus = RadioButtonList2.SelectedItem.Text;
            prfbll.Height = DropDownList1.SelectedItem.Text;
            prfbll.PhysicalStatus = RadioButtonList4.SelectedItem.Text;
            prfbll.Religion = DropDownList2.SelectedItem.Text;
            prfbll.Caste = DropDownList3.SelectedItem.Text;
            prfbll.MotherTongue = DropDownList4.SelectedItem.Text;
            prfbll.Education = DropDownList5.SelectedItem.Text;
            prfbll.Occupation = DropDownList6.SelectedItem.Text;
            prfbll.CountryofResidence = DropDownList8.SelectedItem.Text;
            prfbll.EducationDetails = TextBox3.Text;
            prfbll.AnnualIncome = DropDownList7.SelectedItem.Text;
            prfbll.CountryOfBirth = DropDownList9.SelectedItem.Text;
            prfbll.BirthPlace = TextBox6.Text;
            prfbll.TimeOfBirth = TextBox7.Text;
            prfbll.StarSign = DropDownList10.SelectedItem.Text;
            prfbll.Gothram = TextBox8.Text;
            prfbll.Rassi = DropDownList12.Text;

            if (RadioButtonList2.SelectedItem.Text != "Single")
            {
                prfbll.HavinChildren = RadioButtonList7.SelectedItem.Text;
            }
            else
                {
                    RadioButtonList7.SelectedItem.Text = null;
                }
            }


            try
            {
                chk = ProfileMasterDAL.update(prfbll);
                if (chk >= 0)
                {
                    Response.Write("<script language='javascript'>alert('details updated');</script>");
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
    }


public static int update(ProfileMasterBLL profileMasterBLL)
    {
        SqlParameter uid;
        SqlConnection conn = Generic.DBConnection.OpenConnection();
        try
        {
            SqlCommand cmdd = new SqlCommand("sp_update", conn);
            cmdd.CommandType = CommandType.StoredProcedure;
            cmdd.Parameters.AddWithValue("@FormFiledBy", profileMasterBLL.FormFiledBy);
            cmdd.Parameters.AddWithValue("@MaritalStatus", profileMasterBLL.MaritalStatus);
            cmdd.Parameters.AddWithValue("@Height", profileMasterBLL.Height);
            cmdd.Parameters.AddWithValue("@Religion", profileMasterBLL.Religion);
            cmdd.Parameters.AddWithValue("@Caste", profileMasterBLL.Caste);
            cmdd.Parameters.AddWithValue("@Education", profileMasterBLL.Education);
            cmdd.Parameters.AddWithValue("@Occupation", profileMasterBLL.Occupation);
            cmdd.Parameters.AddWithValue("@CountryofResidence", profileMasterBLL.CountryofResidence);
            cmdd.Parameters.AddWithValue("@EducationDetails", profileMasterBLL.EducationDetails);
            cmdd.Parameters.AddWithValue("@CountryOfBirth", profileMasterBLL.CountryOfBirth);
            cmdd.Parameters.AddWithValue("@BirthPlace", profileMasterBLL.BirthPlace);
            cmdd.Parameters.AddWithValue("@TimeOfBirth", profileMasterBLL.TimeOfBirth);
            cmdd.Parameters.AddWithValue("@StarSign", profileMasterBLL.StarSign);
            cmdd.Parameters.AddWithValue("@Gothram", profileMasterBLL.Gothram);
            cmdd.Parameters.AddWithValue("@Rassi", profileMasterBLL.Rassi);
            cmdd.Parameters.AddWithValue("@HavinChildren", profileMasterBLL.HavinChildren);
            cmdd.Parameters.AddWithValue("@PhysicalStatus", profileMasterBLL.PhysicalStatus);
            cmdd.Parameters.AddWithValue("@MotherTongue", profileMasterBLL.MotherTongue);
            cmdd.Parameters.AddWithValue("@AnnualIncome", profileMasterBLL.AnnualIncome);
            uid = cmdd.Parameters.Add("@id", System.Data.SqlDbType.Int);
            uid.Direction = System.Data.ParameterDirection.Output;
            return cmdd.ExecuteNonQuery();


        }
        catch (Exception ex)
        {

            throw ex;
        }

    }

しかし、問題はDBで値が更新されていないことです。誰かが何が悪いのか教えてもらえますか?

public static int Insert(ProfileMasterBLL profileMasterBLL)
    {
        // bool flag = false;
        SqlParameter pid;
        SqlConnection con = Generic.DBConnection.OpenConnection();

        try
        {

            SqlCommand cmd1 = new SqlCommand("Insertreg", con);
            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.Parameters.AddWithValue("@FirstName", profileMasterBLL.FirstName);
            cmd1.Parameters.AddWithValue("@LastName", profileMasterBLL.LastName);
            cmd1.Parameters.AddWithValue("@Dob", profileMasterBLL.Dob);
            cmd1.Parameters.AddWithValue("@Gender", profileMasterBLL.Gender);
            cmd1.Parameters.AddWithValue("@MobileNo", profileMasterBLL.MobileNo);
            cmd1.Parameters.AddWithValue("@Country", profileMasterBLL.Country);
            cmd1.Parameters.AddWithValue("@State", profileMasterBLL.State);
            cmd1.Parameters.AddWithValue("@EmailId", profileMasterBLL.EmailID);
            cmd1.Parameters.AddWithValue("@Password", profileMasterBLL.Password);
           pid = cmd1.Parameters.Add("@id", System.Data.SqlDbType.Int);
            pid.Direction = System.Data.ParameterDirection.Output;
            return cmd1.ExecuteNonQuery();
4

2 に答える 2

0

あなたの更新手順は更新することを期待しています

where UserId=@id

しかし、あなたはIDを渡していない。

このクラスの場合

ProfileMasterBLL 

ユーザーIDがあり、残りのフィールドを更新するときに割り当てることができます

  if (userid != null)
        {
            prfbll.UserId = userid; //Or whatever it's called
            prfbll.FormFiledBy = RadioButtonList1.SelectedItem.Text;

そうでない場合は、署名を更新する必要があります

public static int update(ProfileMasterBLL profileMasterBLL, string userId)

次に、ユーザーIDも渡します。

これには、パラメータとストアドプロシージャを変更する必要があります。

SPはOUTパラメータをとるべきではありません(したがって、そのように渡されるべきではありません。

    ALTER procedure [dbo].[sp_update]

(@id int ,@FormFiledBy varchar (50),@MaritalStatus varchar (50),@Height varchar (50),
@Religion varchar (50),@Caste varchar (100),
 @MotherTongue varchar(50),@Education varchar (100),@Occupation varchar(50),
 @CountryofResidence varchar (50),@EducationDetails varchar (100),@AnnualIncome varchar(50),
@CountryOfBirth varchar(50),@BirthPlace varchar(50),@TimeOfBirth nchar(10),@StarSign varchar (100),
@Gothram varchar (50),@Rassi varchar(50),@HavinChildren varchar(10),@PhysicalStatus varchar (100))

as
begin

update Profile_Master
 set FormFiledBy=@FormFiledBy,MaritalStatus=@MaritalStatus,Height=@Height,
Religion=@Religion,Caste=@Caste,MotherTongue=@MotherTongue,
Education=@Education,Occupation=@Occupation,CountryofResidence=@CountryofResidence,EducationDetails=@EducationDetails,
AnnualIncome=@AnnualIncome,CountryOfBirth=@CountryOfBirth,BirthPlace=@BirthPlace,TimeOfBirth=@TimeOfBirth,
StarSign=@StarSign,Gothram=@Gothram,Rassi=@Rassi,HavinChildren=@HavinChildren,PhysicalStatus=@PhysicalStatus

where UserId=@id
end

パラメータを追加する必要があります

    SqlParameter uid;
    SqlConnection conn = Generic.DBConnection.OpenConnection();
    try
    {
        SqlCommand cmdd = new SqlCommand("sp_update", conn);
        cmdd.CommandType = CommandType.StoredProcedure;
        cmdd.Parameters.AddWithValue("@Id", userId ); //Or profileMasterBLL.UserId or whatever
        cmdd.Parameters.AddWithValue("@FormFiledBy", profileMasterBLL.FormFiledBy);
        cmdd.Parameters.AddWithValue("@MaritalStatus", profileMasterBLL.MaritalStatus);
        cmdd.Parameters.AddWithValue("@Height", profileMasterBLL.Height);
        cmdd.Parameters.AddWithValue("@Religion", profileMasterBLL.Religion);
        cmdd.Parameters.AddWithValue("@Caste", profileMasterBLL.Caste);
        cmdd.Parameters.AddWithValue("@Education", profileMasterBLL.Education);
        cmdd.Parameters.AddWithValue("@Occupation", profileMasterBLL.Occupation);
        cmdd.Parameters.AddWithValue("@CountryofResidence", profileMasterBLL.CountryofResidence);
        cmdd.Parameters.AddWithValue("@EducationDetails", profileMasterBLL.EducationDetails);
        cmdd.Parameters.AddWithValue("@CountryOfBirth", profileMasterBLL.CountryOfBirth);
        cmdd.Parameters.AddWithValue("@BirthPlace", profileMasterBLL.BirthPlace);
        cmdd.Parameters.AddWithValue("@TimeOfBirth", profileMasterBLL.TimeOfBirth);
        cmdd.Parameters.AddWithValue("@StarSign", profileMasterBLL.StarSign);
        cmdd.Parameters.AddWithValue("@Gothram", profileMasterBLL.Gothram);
        cmdd.Parameters.AddWithValue("@Rassi", profileMasterBLL.Rassi);
        cmdd.Parameters.AddWithValue("@HavinChildren", profileMasterBLL.HavinChildren);
        cmdd.Parameters.AddWithValue("@PhysicalStatus", profileMasterBLL.PhysicalStatus);
        cmdd.Parameters.AddWithValue("@MotherTongue", profileMasterBLL.MotherTongue);
        cmdd.Parameters.AddWithValue("@AnnualIncome", profileMasterBLL.AnnualIncome);

また、これらのuid = cmdd.Parameters.Add( "@ id"、System.Data.SqlDbType.Int);を削除します。uid.Direction = System.Data.ParameterDirection.Output; cmdd.ExecuteNonQuery();を返します。

于 2012-08-07T16:34:51.297 に答える
0
  1. 更新 sp の @id パラメータから出力引数を削除します
  2. C# の update メソッドで @id の値を設定します
于 2012-08-07T16:28:30.467 に答える