Results 1 to 7 of 7

Thread: Sharing connections

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    37

    Sharing connections

    Hi.

    What is the best way to share a connection among multiple pages? I need to open a DataSet on one page for reading, but if my user needs to change the data, he will open another page with the selected data for editing. Is it possible?

    Thanks,

    Robert

  2. #2
    Lively Member
    Join Date
    Aug 2002
    Location
    outerspace
    Posts
    126
    There is not really any way to do this on different pages using the same connection being that eash page is independently complied piece of code. As far as writng less code you could always make a com object too reuse code. That or you can edit and view data ont he same page. the data grid allows you to easily do this
    "All those who wonder are not lost" -j.r.r tolkien

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you are going about it the wrong way. when someone selects a record to edit, you pass an id, or other identifier for the record, to the other page via a querystring, cache object, varaible, etc. Then you open a new connection to the databse using an sql statement that gets the record. You NEVER ,,,EVER keep a database connection open across pages. Do not even attempt to keep finding out how as any good programmer will tell you the same thing.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346
    you are going about it the wrong way. when someone selects a record to edit, you pass an id, or other identifier for the record, to the other page via a querystring, cache object, varaible, etc. Then you open a new connection to the databse using an sql statement that gets the record. You NEVER ,,,EVER keep a database connection open across pages. Do not even attempt to keep finding out how as any good programmer will tell you the same thing.
    I Agree....
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    37
    Hi Chris.

    I understand what you say. My customer wants a grid to list the records, but wants to edit them on another page. I have a DataReader to fill the grid, so your advice is to pass an ID of the selected record to the new page and open my DataSet there, is it?

    Thanks,

    Robert

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    yes that is it exactly. You can pass it to the next page using a querystring and get the value using request.querystring. Then just build your SQL statement to pull, update, edit, etc. whatever record has that 'id'. I assume you have some kind of unique identifier for your records.

    just in case you dont know about querystrings.

    Add a querystring to a url:

    http://yousite.com/mypage.aspx?id=whatever

    then use Request.Querystring("id") to get that value.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    37
    Thanks Chris.

    Robert Scheer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width