Answered by:
Append Info

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
- 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);
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