I am a newbie using C# and webmatrix. I have several rows within a database with 2 coloumns. I want to query the database and place the values in two variables, 1 for coloum A the other for coloumn B. I was hoping to use a datareader but if there is an easier way then i will go with that. As the number of rows in the table change from time to time, i was hoping to use an array to assign the db values to. From previously using Java, i know that array sizes must be specified when created so usually used vectors. Is this also true with c# and can vectors be used? Finally is it possible then to assign the "vector" as a session variable?
Could someone please help me out with this please, if ye have any question please ask.You should use the datagrid and bind it to a dataset. You don't need to do any looping thanks to databinding. the general flow is .. create a connection to database, use dataadapter to retrieve data, use a dataset to hold data, bind a datagrid ( or datalist, or repeater) to the dataset. You can set paging in the datagrid to show a number of rows per page. you could do all this with little code.
check out tutorials on databinding a datagrid
http://www.dotnetjunkies.com/QuickStart/aspplus/default.aspx?url=/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datagrid/doc_datagrid.aspx
Ok I dont think i explained myself correctly. Why i want to let it equal to variables is because i want to use it in multiple pages and why i want to use the session object is because i want to minimize hits on the database. So for this reason I am hope to use a class when a new session is created and populate the "variables". And continue on and only assign the variables again when the session ends.
Also the values i require, include a name, link address and a description. A such only the name will be displayed on screen with the other 2 being the href and alt respectively.
I know i am probably not explaining myself very well but do people understand??
I create a DataTable in an Application variable during Application_OnStart in my Global.asax file. I also check it again on each Seesion_OnStart just to make sure the DataTable is Ok if not I call the function again.
C#
DB code here...DataTable list_contents = new DataTable();
connGalleryList.Open();
MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter();
adapter.SelectCommand = dbCommGalleryList;
adapter.Fill(list_contents);
connGalleryList.Close();Application["galleryTable"] = list_contents;
list_contents.Dispose();
0 comments:
Post a Comment