title: How to pass a Session to a DataTable?
body: <p>In my asp project I need to write all Items form the list box into database table using TVP. I have listbox, stored procedure (passing TVP - Table Valued Parameters). The main problem is that passing DataTable is NULL, but the Session isn't. I'll send you my code form aspx.cs file (only one block, if you'll nedd more, let me know).</p>
  
  <pre><code>protected void ASPxButton1_Click(object sender, EventArgs e)
  {
      //DataTable dts = Session["SelectedOptions"] as DataTable;
  
      DataTable _dt;
      //_dt = new DataTable("Items");
      _dt = Session["SelectedOptions"] as DataTable;
      _dt.Columns.Add("Id", typeof(int));
      _dt.Columns.Add("Name", typeof(string));
  
      foreach (ListEditItem item in lbSelectedOptions.Items)
      {
          DataRow dr = _dt.NewRow();
          dr["Id"] = item.Value;
          dr["Name"] = item.Text;
      }
      SqlConnection con;
      string conStr = ConfigurationManager.ConnectionStrings["TestConnectionString2"].ConnectionString;
      con = new SqlConnection(conStr);
      con.Open();
  
      using (con)
      {
          SqlCommand sqlCmd = new SqlCommand("TestTVP", con);
          sqlCmd.CommandType = CommandType.StoredProcedure;
          SqlParameter tvpParam = sqlCmd.Parameters.AddWithValue("@testtvp", _dt);
          tvpParam.SqlDbType = SqlDbType.Structured;
          sqlCmd.ExecuteNonQuery();
      }
      con.Close();
  
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p><a href="http://i.stack.imgur.com/Ivv1U.png" rel="nofollow">Debugging Screenshot</a></p>