Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi am using dynamic in my web application..
am using user control(BidTree)
i want to save this user controls values from session to sql table can any one suggest me how to give code to save into sql table.

thanks.
Posted
Updated 23-Oct-17 6:36am
Comments
Herman<T>.Instance 21-Aug-14 6:06am    
what have you tried? You can read values from session, set them as SqlParameter and fire a query with thee parameters to your database table? What part is to hard to handle for you?

Adding DataTable into Session Veriable:

Set into Session variable as

Session["MyDataTableSessionName"]= "MyDataTable"

i.e. DataTable myDataTable=new DataTable();

Session["MyDataTable"]= myDataTable;

Retrive that DataTable from Session:

DataTable myDataTable =(DataTable)Session["MyDataTable"];
 
Share this answer
 
Lets say you have a datatable ad you want to save it, say Dt.
C#
Session["myTable"] = Dt;

Now on the page where you need to access it:
C#
DataTable table = Session["myTable"] as DataTable;

if(table != null)
{
 //read table and push in Sqlserver
}
else
{
 //session either expired or invalid page being accessed.
}

I hope it helps. let me know if you need more.
 
Share this answer
 
Adding DataTable into Session:
C#
DataTable Tissues = new DataTable();

Tissues = dal.returnTissues("TestID", "TestValue");// returnTissues("","") sample     function for adding values

Session.Add("Tissues", Tissues);


Retrive that datatable from session:
C#
DataTable Tissues = Session["Tissues"] as DataTable

Or
C#
DataTable Tissues = (DataTable)Session["Tissues"];

Ref:Storing and retrieving datatable from session[^]
 
Share this answer
 
Comments
ythisbug 8-Jun-12 5:42am    
thanks can u explain me,.wat is TestID,TestValue ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900