locked
Append Info RRS feed

  • Question

  • User-561144170 posted

    Step 1.)  I've built a web page that enables users to search an access database using several criteria, choose one of the forms returned and write their selected info to a "new" table within Access.

    So far, so good... 

    Now, I want to enable the users to proceed to another webpage, fill in three text boxes and with a Button control, write this new info to the table I generated in step 1.)

    What's the typical methodology to accomplish this? 

    What should I use as an identifier on this record?  Autonumber?  High value integer?

    Code?

    MANY thanks !!

    Thursday, July 29, 2010 5:35 PM

Answers

  • User-1734649046 posted

    Hi,

    Please refer following

    DataTable dt = new DataTable();
    DataRow dr;
    
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Value", typeof(string));
    
    dr = dt.NewRow();
    dr["Id"] = 1;
    dr["Value"] = "Value1";
    dt.Rows.Add(dr);
    
    dr = dt.NewRow();
    dr["Id"] = 2;
    dr["Value"] = "Value2";
    dt.Rows.Add(dr);
    
    //store datatable in session
    Session["DataSource"] = dt;
    
    //variable used to store maxid
    int intMaxId = 1;
    
    //get max id from datatable
    DataRow[] maxId = dt.Select("Id = Max(Id)");
    
    //check if maxid contains data
    if (maxId != null && maxId.Length > 0)
    {
        if (maxId[0]["Id"] != null && maxId[0]["Id"] != DBNull.Value)
        {
            //get max id increment it by 1 to get next id
            intMaxId = Convert.ToInt16(maxId[0]["Id"].ToString()) + 1;
        }
    }
    
    //store auto incremented id in datatable
    dr = dt.NewRow();
    dr["Id"] = intMaxId;
    dr["Value"] = "Value";
    dt.Rows.Add(dr);

    hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 30, 2010 2:14 AM

All replies

  • User-1734649046 posted

    Hi,

    You can use DataTable and store it in Session. Please refer following

    DataTable dt = new DataTable();
    DataRow dr;
    
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Value", typeof(string));
    
    dr = dt.NewRow();
    dr["Id"] = 1;
    dr["Value"] = "Value1";
    dt.Rows.Add(dr);
    
    dr = dt.NewRow();
    dr["Id"] = 2;
    dr["Value"] = "Value2";
    dt.Rows.Add(dr);
    
    //store datatable in session
    Session["DataSource"] = dt;


    You can access session variable across pages.

    hope this helps

    Thursday, July 29, 2010 11:15 PM
  • User-561144170 posted

    Thanks for the reply !

    So the user chooses a return from the database, enters it and thereby generates a new record, trigger the "Autonumber" field...

    This puppy picks up the "Autonumber" generated, retains it throughout the user session and enables additional content to be addended to the record created ??

    Have I got that right ? 

    Friday, July 30, 2010 1:28 AM
  • User-1734649046 posted

    Hi,

    Please refer following

    DataTable dt = new DataTable();
    DataRow dr;
    
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Value", typeof(string));
    
    dr = dt.NewRow();
    dr["Id"] = 1;
    dr["Value"] = "Value1";
    dt.Rows.Add(dr);
    
    dr = dt.NewRow();
    dr["Id"] = 2;
    dr["Value"] = "Value2";
    dt.Rows.Add(dr);
    
    //store datatable in session
    Session["DataSource"] = dt;
    
    //variable used to store maxid
    int intMaxId = 1;
    
    //get max id from datatable
    DataRow[] maxId = dt.Select("Id = Max(Id)");
    
    //check if maxid contains data
    if (maxId != null && maxId.Length > 0)
    {
        if (maxId[0]["Id"] != null && maxId[0]["Id"] != DBNull.Value)
        {
            //get max id increment it by 1 to get next id
            intMaxId = Convert.ToInt16(maxId[0]["Id"].ToString()) + 1;
        }
    }
    
    //store auto incremented id in datatable
    dr = dt.NewRow();
    dr["Id"] = intMaxId;
    dr["Value"] = "Value";
    dt.Rows.Add(dr);

    hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 30, 2010 2:14 AM
  • User-561144170 posted

    Many thanks for the reply !

    Does this code reside behind the first web page?  The second?  Or both?  

    Saturday, July 31, 2010 5:41 AM
  • User-1734649046 posted

    Hi,

    You need to add it in both pages. Since you need combined result set in Session DataTable. So that MaxId will be unique.

    hope this helps


    Saturday, July 31, 2010 5:45 AM
  • User-561144170 posted

    Hi,

    Please refer following

     

    1. DataTable dt = new DataTable();   
    2. DataRow dr;   
    3.   
    4. dt.Columns.Add("Id"typeof(int));   
    5. dt.Columns.Add("Value"typeof(string));   
    6.   
    7. dr = dt.NewRow();   
    8. dr["Id"] = 1;   
    9. dr["Value"] = "Value1";   
    10. dt.Rows.Add(dr);   
    11.   
    12. dr = dt.NewRow();   
    13. dr["Id"] = 2;   
    14. dr["Value"] = "Value2";   
    15. dt.Rows.Add(dr);   
    16.   
    17. //store datatable in session   
    18. Session["DataSource"] = dt;   
    19.   
    20. //variable used to store maxid   
    21. int intMaxId = 1;   
    22.   
    23. //get max id from datatable   
    24. DataRow[] maxId = dt.Select("Id = Max(Id)");   
    25.   
    26. //check if maxid contains data   
    27. if (maxId != null && maxId.Length > 0)   
    28. {   
    29.     if (maxId[0]["Id"] != null && maxId[0]["Id"] != DBNull.Value)   
    30.     {   
    31.         //get max id increment it by 1 to get next id   
    32.         intMaxId = Convert.ToInt16(maxId[0]["Id"].ToString()) + 1;   
    33.     }   
    34. }   
    35.   
    36. //store auto incremented id in datatable   
    37. dr = dt.NewRow();   
    38. dr["Id"] = intMaxId;   
    39. dr["Value"] = "Value";   
    40. dt.Rows.Add(dr);  
    DataTable dt = new DataTable();
    DataRow dr;
    
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Value", typeof(string));
    
    dr = dt.NewRow();
    dr["Id"] = 1;
    dr["Value"] = "Value1";
    dt.Rows.Add(dr);
    
    dr = dt.NewRow();
    dr["Id"] = 2;
    dr["Value"] = "Value2";
    dt.Rows.Add(dr);
    
    //store datatable in session
    Session["DataSource"] = dt;
    
    //variable used to store maxid
    int intMaxId = 1;
    
    //get max id from datatable
    DataRow[] maxId = dt.Select("Id = Max(Id)");
    
    //check if maxid contains data
    if (maxId != null && maxId.Length > 0)
    {
        if (maxId[0]["Id"] != null && maxId[0]["Id"] != DBNull.Value)
        {
            //get max id increment it by 1 to get next id
            intMaxId = Convert.ToInt16(maxId[0]["Id"].ToString()) + 1;
        }
    }
    
    //store auto incremented id in datatable
    dr = dt.NewRow();
    dr["Id"] = intMaxId;
    dr["Value"] = "Value";
    dt.Rows.Add(dr);


    hope this helps

     

     

    I've been trying to figure this out and it seems to be way over my head at this point.

    Questions

    1.)  Do I need additional objects on the page other than the "detailsview" I am using to manually insert data into Access?

    2.)  Do I need to build a datatable for this to work with or does this code do it for me?

    3.)  I am assuming that I need to add a field from the database for each "value" you specify above?

    4.)  Is the "key" field (in this case an "autonumber" field from my database) treated or denoted any differently than the others?  I have to hold this one in memory to be able to write to the same record.

    These are probably stupid questions, but I'm new to this and feeling my way along...

    Many thanks !

    Wednesday, August 11, 2010 3:20 AM