Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save a record in a variable, then display record later

Status
Not open for further replies.

ola123

Technical User
Sep 16, 2005
52
JM
Hello world,
in programming anything is possible, right?

anyway
my script searches a database for a record based on a criteria value(which is a variable) then save the record in a variable record
if thats even possible.

A value is saved to the variable whenever you ask for one particular field, but that doesn't work when its an entire record.

Any suggestions/ideas on how to save an entire record then display it later
( i was thinking that i needed a array or save it one by one or something )

what i have is below NB this doesn't work
Code:
Sub display(x as object, y as eventargs)
        
        Dim value As String
        Dim Record as srting 
        Dim DBConnection As Data.OleDb.OleDbConnection
        Dim DBCommand As Data.OleDb.OleDbCommand
        
        value = txtInput.Text
                
        DBConnection = New Data.OleDb.OleDbConnection( _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & Server.MapPath("PCC.mdb"))
        DBConnection.Open()
        
        record = "SELECT * FROM Accounts " & "WHERE id = '" & value & "'"
        DBCommand = New OleDbCommand(record, DBConnection)
        value = DBCommand.ExecuteScalar
        
        DBConnection.Close()
    End Sub
.......

<form>
<asp:textbox runat=server id=txtinput />
<asp:button runat=server id=btn onclick=display />
</form>
Im thinking that it would look somthing like the above

secondly,

if i there was (is) a was to save the record in a variable how would one go about displaying it. And can it be displayed using a gridview.

thanks in advance,
if there is an easier way of doing the above i am open to all suggestions.

thanks v. much
Cool nuh Man
 
If you want to "save" a row of data, you will have to execute your sql, and return a datatable. Basically this datatable will only contain one row from what I understand from your post. What you can do is store the dataset or datatable in a session variable. Then you can access the session variable at anytime, on any page. Then you can bind it to a grid, repeater.. etc.
 
thanks for the advice jbenson001,

it seems u understand what i am trying to say,
but the thing is i dont really understand everything you are saying.

So do you have any links or tutorials i could use for reference


thanks again,
Cool Nuh Man
 
One thing to keep in mind is that DataSets, DataTables and DataRows are all quite large objects and storing them as part of a user session can eat up memory resources quickly if you have a large number of users.

You may want to look into first converting the row (if it is only one row by design) into a much lighter weight object such as a "NameValueCollection". This object is very easy to use, low memory, and has essentially 2 columns (Key(or Name)= your data row field name, Value= your data row field value). Then store that NVC object into the session variable.

Food for thought anyway. ;o)

Senior Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top