| | |
Variables
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
Use ADO.NET to get data from the database.
I recommend you create a custom class that has a property for each of the data columns. Iterate the database resultset (be it a SqlDataReader or DataTable or whatever) and create an array of your custom class. One per record. Assign the array to the Session.
You could of course just bung the disconnected DataTable or DataSet straight into the session variable. But, they don't serialize very efficiently. I would not recommend this approach if your application has a lot of users say more than 25.
I recommend you create a custom class that has a property for each of the data columns. Iterate the database resultset (be it a SqlDataReader or DataTable or whatever) and create an array of your custom class. One per record. Assign the array to the Session.
You could of course just bung the disconnected DataTable or DataSet straight into the session variable. But, they don't serialize very efficiently. I would not recommend this approach if your application has a lot of users say more than 25.
•
•
Join Date: Dec 2007
Posts: 2
Reputation:
Solved Threads: 0
add using System.Data.SqlClient;
and add following table data
try
{
int CustomerID;
string CompanyName;
SqlConnection con = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
SqlCommand cmd = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", con);
cmd.CommandTimeout = 30;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
con.Open();
DataSet ds = new DataSet();
da.Fill(ds, "Customers");
if (ds != null)
{
DataTable dt = ds.Tables[0];
if (dt != null)
{
DataRow dr = dt.Rows[0];
if (dr["CustomerID"].ToString() != "")
{
CustomerID = int.Parse(dr["CustomerID"].ToString());
}
if (dr["CompanyName"].ToString() != "")
{
CompanyName = dr["CompanyName"].ToString();
}
}
}
con.Close();
}
catch (Exception)
{
throw;
}
and add following table data
try
{
int CustomerID;
string CompanyName;
SqlConnection con = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
SqlCommand cmd = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", con);
cmd.CommandTimeout = 30;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
con.Open();
DataSet ds = new DataSet();
da.Fill(ds, "Customers");
if (ds != null)
{
DataTable dt = ds.Tables[0];
if (dt != null)
{
DataRow dr = dt.Rows[0];
if (dr["CustomerID"].ToString() != "")
{
CustomerID = int.Parse(dr["CustomerID"].ToString());
}
if (dr["CompanyName"].ToString() != "")
{
CompanyName = dr["CompanyName"].ToString();
}
}
}
con.Close();
}
catch (Exception)
{
throw;
}
![]() |
Similar Threads
- multiple variables in a mod_rewrite URL string (Linux Servers and Apache)
- Problem with variables in Windows shell script (Windows NT / 2000 / XP)
- how to get pass url variables from one page to another page with out knowing them? (ColdFusion)
- how to declare two integer variables x and y (C)
- Retreiving variables from a sql query into a form (PHP)
- Problem Unsetting Variables? (PHP)
Other Threads in the ASP.NET Forum
- Previous Thread: Excel integration with the ASP.net over VB
- Next Thread: HyperLink MouseOver
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol advice ajax alltypeofvideos anathor appliances application asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions dataaccesslayer database datagridview datagridviewcheckbox datalist development dgv dialog dropdownlist dynamically edit expose feedback fileuploader fill flash form formatdecimal formview google grid gridview gudi iframe iis image javascript list listbox login microsoft mono mouse mssql news numerical opera panelmasterpagebuttoncontrols parent project radio redirect registration relationaldatabases reportemail richtextbox save schoolproject search security select sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking treeview unauthorized validatedate validation vb.net video videos view vista visualstudio web webapplications webdevelopemnt webprogramming webservice xsl youareanotmemberofthedebuggerusers






