我有一个两页的注册表,第一页中输入的数据存储在一个会话中.我想在下一页中使用此会话将数据输入到表中,但是... [英] I have a registration form with 2 pages the data which is entered in the first page is stored in a session.I want to use this session in the next page to enter the data in to the table.but it...

查看:71
本文介绍了我有一个两页的注册表,第一页中输入的数据存储在一个会话中.我想在下一页中使用此会话将数据输入到表中,但是...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码

Here is the code

if (Session["userregdt"] != null)
      {


          if (ssConnection.State == ConnectionState.Closed)
          {
              ssConnection.Open();
          }
          SqlCommand cmd1 = new SqlCommand("Select * from Property where ProfileId=@profileId", ssConnection);
          cmd1.Parameters.Add("@profileId", SqlDbType.VarChar).Value = Session["userprofileid"];
          SqlDataAdapter da = new SqlDataAdapter(cmd1);
          DataTable dt = new DataTable();
          da.Fill(dt);
          if (dt.Rows.Count > 0)
          {
          }
          else if (dt.Rows.Count <= 0)
          {



                  SqlCommand cmd = new SqlCommand();
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.CommandText = "InsertListProperty";
                  cmd.Connection = ssConnection;
                  DataTable regdt = new DataTable();
                 Session["userregdt"] = regdt;


                  cmd.Parameters.Add("@profileId", SqlDbType.VarChar).Value =regdt.Rows[0]["profileid"];
                  cmd.Parameters.Add("@nature", SqlDbType.VarChar).Value = regdt.Rows[0]["Nature"];
                  cmd.Parameters.Add("@propertyType", SqlDbType.VarChar).Value =regdt.Rows[0]["PropertyType"];
                  cmd.Parameters.Add("@transactionType", SqlDbType.VarChar).Value = regdt.Rows[0]["TransactionType"];
                  cmd.Parameters.Add("@location", SqlDbType.VarChar).Value = regdt.Rows[0]["Location"];
                  cmd.Parameters.Add("@area", SqlDbType.Int).Value = regdt.Rows[0]["Area"];
                  cmd.Parameters.Add("@totalPrice", SqlDbType.Int).Value = regdt.Rows[0]["TotalPrice"];
                  cmd.Parameters.Add("@negotiablePrice", SqlDbType.VarChar).Value = regdt.Rows[0]["NegotiablePrice"];
                  cmd.Parameters.Add("@furnished", SqlDbType.VarChar).Value = regdt.Rows[0]["Furnished"];
                  cmd.Parameters.Add("@bedRooms", SqlDbType.Int).Value = regdt.Rows[0]["BedRooms"];
                  cmd.Parameters.Add("@bathRooms", SqlDbType.Int).Value = regdt.Rows[0]["BathRooms"];
                  cmd.Parameters.Add("@floor", SqlDbType.VarChar).Value = regdt.Rows[0]["Floor"];
                  cmd.Parameters.Add("@totalFloors", SqlDbType.Int).Value = regdt.Rows[0]["TotalFloors"];
                  cmd.Parameters.Add("@possessionStatus", SqlDbType.VarChar).Value = regdt.Rows[0]["PossessionStatus"];
                  cmd.Parameters.Add("@briefDescription", SqlDbType.VarChar).Value = regdt.Rows[0]["BriefDescription"];

                  cmd.ExecuteNonQuery();


          }

      }



[edit]已添加代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

尽管问题不完整,但根据您发布的代码,我在这里看到了逻辑流程:
Though question is incomplete, but based on the code you have posted, I see a logical flow here:
DataTable regdt = new DataTable();
Session["userregdt"] = regdt;



在会话中填充数据表以分配各种参数的位置应该相反.

试试:



It should be opposite where you populate the datatable from session to assign various parameters.

Try:

..
..
..
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "InsertListProperty";
cmd.Connection = ssConnection;
DataTable regdt = new DataTable();
regdt = (DataTable)Session["userregdt"];                   
 
cmd.Parameters.Add("@profileId", SqlDbType.VarChar).Value =regdt.Rows[0]["profileid"];
cmd.Parameters.Add("@nature", SqlDbType.VarChar).Value = regdt.Rows[0]["Nature"];
..
..


这样,您可以从会话中填充数据并使用它.

顺便说一句,这里涉及的不良编程习惯很少,但是您的问题现在应该可以解决.


This way, you can populate your data back from session and use it.

BTW, there are few bad programming practices involved here but your issue should get resolved for now.


这篇关于我有一个两页的注册表,第一页中输入的数据存储在一个会话中.我想在下一页中使用此会话将数据输入到表中,但是...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆