Ok, but when you pass a parameter(s) (often called url querydefs), it does not automatic go into session.
and for things like a database row PK id, for reasons of security, you probably don't want to show or have such values int the URL (unless everyone and anyone is allowed to view such records, else other users can change that value, and thus view other people's records.
But, the basic issue here seems to be the assumption that passing such values in the URL by magic goes into Session(). they have ZERO relationship to each other.
Now, if the calling page were to set session() (and that is a very good idea), then you would not require nor need the "ID" to be passed in the URL anymore, would you?
So, based on the above information, then your code would be something like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
LoadData();
}
void LoadData()
{
// Check for value in URL
string docnum = "";
if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
// we have URL "?id=xxxxx"
docnum = Request.QueryString["ID"].ToString();
else
// no url id, try for session
if (Session["record"] != null)
docnum = Session["record"].ToString();
// optional - we don't have ID or session - go somepalce else
if (docnum == "")
//{
// // no URL, no session, we should jump back to previouis
// Response.Redirect("myscan.aspx");
return;
//}
DataTable rstData = new DataTable();
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
{
string strSQL
= "SELECT Item,Qty,Rate,Amount FROM Table WHERE doc_no = @docNum";
using (SqlCommand cmdSQL = new SqlCommand(strSQL, conn))
{
cmdSQL.Parameters.Add("@docNum", SqlDbType.NVarChar).Value = docnum;
conn.Open();
rstData.Load(cmdSQL.ExecuteReader());
}
}
if (rstData.Rows.Count > 0)
{
// We have data - do whatever
General.FLoader(EditRecord, rstData.Rows[0]);
}
}
So, above should quite much give you a close working bit of code
Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta Canada