Updating 2 Tables at once

Discussion in 'ASP .Net' started by MRW, Aug 20, 2006.

  1. MRW

    MRW Guest

    Quick question for anybody who can help:

    I have two tables:

    tblUsers
    --------
    UserID
    Name

    tblPhones
    ---------
    PhoneID
    UserID
    PhoneNumber

    If I'm collecting the name and the phone numbers (can be multiple
    numbers) in one form, what's the best way of placing it in the
    database? The question revolves around the UserID and making sure the
    tblPhones.UserID = tblUsers.UserID

    Thanks for any help!
    MRW, Aug 20, 2006
    #1
    1. Advertising

  2. MRW

    MRW Guest

    Oh yes... tblUsers.UserID is automatically incremented in the
    database...

    MRW wrote:
    > Quick question for anybody who can help:
    >
    > I have two tables:
    >
    > tblUsers
    > --------
    > UserID
    > Name
    >
    > tblPhones
    > ---------
    > PhoneID
    > UserID
    > PhoneNumber
    >
    > If I'm collecting the name and the phone numbers (can be multiple
    > numbers) in one form, what's the best way of placing it in the
    > database? The question revolves around the UserID and making sure the
    > tblPhones.UserID = tblUsers.UserID
    >
    > Thanks for any help!
    MRW, Aug 20, 2006
    #2
    1. Advertising

  3. MRW

    Mark Rae Guest

    "MRW" <> wrote in message
    news:...

    > Quick question for anybody who can help:
    >
    > I have two tables:
    >
    > tblUsers
    > --------
    > UserID
    > Name
    >
    > tblPhones
    > ---------
    > PhoneID
    > UserID
    > PhoneNumber
    >
    > If I'm collecting the name and the phone numbers (can be multiple
    > numbers) in one form, what's the best way of placing it in the
    > database? The question revolves around the UserID and making sure the
    > tblPhones.UserID = tblUsers.UserID
    >
    > Thanks for any help!


    Is the UserID already known, or are you adding one record to tblUsers and
    one or more to tblPhones? If the former, is tblUsers.UserID an identity
    field? If so, you can retrieve the identity by SELECT @@IDENTIY or SELECT
    SCOPE_IDENTITY. Then you can use that to pump the records into tblPhones.
    Mark Rae, Aug 20, 2006
    #3
  4. Based on that fact that you mention that the UserID is an auto
    incremented field, I am assuming this is an IDENTITY and the SELECT
    @@IDENTITY in your SQL should do it for you.

    MRW wrote:
    > Quick question for anybody who can help:
    >
    > I have two tables:
    >
    > tblUsers
    > --------
    > UserID
    > Name
    >
    > tblPhones
    > ---------
    > PhoneID
    > UserID
    > PhoneNumber
    >
    > If I'm collecting the name and the phone numbers (can be multiple
    > numbers) in one form, what's the best way of placing it in the
    > database? The question revolves around the UserID and making sure the
    > tblPhones.UserID = tblUsers.UserID
    >
    > Thanks for any help!
    Sarat Pediredla, Aug 20, 2006
    #4
  5. MRW

    MRW Guest

    Thanks for the feedback!

    I'll be honest. I'm not familiar with the @@IDENTITY. Can you give a
    quick example on how it is used (VB)?

    Thank you for the help!

    Sarat Pediredla wrote:
    > Based on that fact that you mention that the UserID is an auto
    > incremented field, I am assuming this is an IDENTITY and the SELECT
    > @@IDENTITY in your SQL should do it for you.
    >
    > MRW wrote:
    > > Quick question for anybody who can help:
    > >
    > > I have two tables:
    > >
    > > tblUsers
    > > --------
    > > UserID
    > > Name
    > >
    > > tblPhones
    > > ---------
    > > PhoneID
    > > UserID
    > > PhoneNumber
    > >
    > > If I'm collecting the name and the phone numbers (can be multiple
    > > numbers) in one form, what's the best way of placing it in the
    > > database? The question revolves around the UserID and making sure the
    > > tblPhones.UserID = tblUsers.UserID
    > >
    > > Thanks for any help!
    MRW, Aug 20, 2006
    #5
  6. I feel generous today, so here you go. 2 mins on Google could have got
    you that.

    http://support.microsoft.com/default.aspx?scid=kb;en-us;815629

    MRW wrote:
    > Thanks for the feedback!
    >
    > I'll be honest. I'm not familiar with the @@IDENTITY. Can you give a
    > quick example on how it is used (VB)?
    >
    > Thank you for the help!
    >
    > Sarat Pediredla wrote:
    > > Based on that fact that you mention that the UserID is an auto
    > > incremented field, I am assuming this is an IDENTITY and the SELECT
    > > @@IDENTITY in your SQL should do it for you.
    > >
    > > MRW wrote:
    > > > Quick question for anybody who can help:
    > > >
    > > > I have two tables:
    > > >
    > > > tblUsers
    > > > --------
    > > > UserID
    > > > Name
    > > >
    > > > tblPhones
    > > > ---------
    > > > PhoneID
    > > > UserID
    > > > PhoneNumber
    > > >
    > > > If I'm collecting the name and the phone numbers (can be multiple
    > > > numbers) in one form, what's the best way of placing it in the
    > > > database? The question revolves around the UserID and making sure the
    > > > tblPhones.UserID = tblUsers.UserID
    > > >
    > > > Thanks for any help!
    Sarat Pediredla, Aug 20, 2006
    #6
  7. Ok, looks like I pasted a dummy link there. Here is another go.

    http://www.informit.com/articles/article.asp?p=382852&seqNum=4&rl=1

    MRW wrote:
    > Thanks for the feedback!
    >
    > I'll be honest. I'm not familiar with the @@IDENTITY. Can you give a
    > quick example on how it is used (VB)?
    >
    > Thank you for the help!
    >
    > Sarat Pediredla wrote:
    > > Based on that fact that you mention that the UserID is an auto
    > > incremented field, I am assuming this is an IDENTITY and the SELECT
    > > @@IDENTITY in your SQL should do it for you.
    > >
    > > MRW wrote:
    > > > Quick question for anybody who can help:
    > > >
    > > > I have two tables:
    > > >
    > > > tblUsers
    > > > --------
    > > > UserID
    > > > Name
    > > >
    > > > tblPhones
    > > > ---------
    > > > PhoneID
    > > > UserID
    > > > PhoneNumber
    > > >
    > > > If I'm collecting the name and the phone numbers (can be multiple
    > > > numbers) in one form, what's the best way of placing it in the
    > > > database? The question revolves around the UserID and making sure the
    > > > tblPhones.UserID = tblUsers.UserID
    > > >
    > > > Thanks for any help!
    Sarat Pediredla, Aug 20, 2006
    #7
  8. MRW

    MRW Guest

    Great! Thanks a lot!


    Sarat Pediredla wrote:
    > Ok, looks like I pasted a dummy link there. Here is another go.
    >
    > http://www.informit.com/articles/article.asp?p=382852&seqNum=4&rl=1
    >
    > MRW wrote:
    > > Thanks for the feedback!
    > >
    > > I'll be honest. I'm not familiar with the @@IDENTITY. Can you give a
    > > quick example on how it is used (VB)?
    > >
    > > Thank you for the help!
    > >
    > > Sarat Pediredla wrote:
    > > > Based on that fact that you mention that the UserID is an auto
    > > > incremented field, I am assuming this is an IDENTITY and the SELECT
    > > > @@IDENTITY in your SQL should do it for you.
    > > >
    > > > MRW wrote:
    > > > > Quick question for anybody who can help:
    > > > >
    > > > > I have two tables:
    > > > >
    > > > > tblUsers
    > > > > --------
    > > > > UserID
    > > > > Name
    > > > >
    > > > > tblPhones
    > > > > ---------
    > > > > PhoneID
    > > > > UserID
    > > > > PhoneNumber
    > > > >
    > > > > If I'm collecting the name and the phone numbers (can be multiple
    > > > > numbers) in one form, what's the best way of placing it in the
    > > > > database? The question revolves around the UserID and making sure the
    > > > > tblPhones.UserID = tblUsers.UserID
    > > > >
    > > > > Thanks for any help!
    MRW, Aug 20, 2006
    #8
  9. MRW

    Mark Rae Guest

    "MRW" <> wrote in message
    news:...

    > Great! Thanks a lot!


    Sarat's comment about Google is very relevant, though... you really could
    have found this out for yourself in a matter of seconds...
    Mark Rae, Aug 20, 2006
    #9
  10. MRW

    MRW Guest

    I've been on Google searching for things for hours. I did not find
    anything that would have led me to @@IDENTITY. So when he told me, I
    simply asked if he had a quick example on how to use it while I've got
    him.


    Mark Rae wrote:
    > "MRW" <> wrote in message
    > news:...
    >
    > > Great! Thanks a lot!

    >
    > Sarat's comment about Google is very relevant, though... you really could
    > have found this out for yourself in a matter of seconds...
    MRW, Aug 21, 2006
    #10
  11. MRW

    JT Guest

    To Mark & Sarat:

    We all appreciate your help. And I try to help when I can. Isn't that
    why this group is here? If we are just going to tell people to go look
    on Google, why does this group exist? I'm sure you're both very
    helpful and generous in most cases. If you were a guru sitting on a
    mountaintop and someone climbed up to ask a question, wouldn't you
    think they were an idiot if they climbed back down and then had to
    climb back up to ask a follow-up question instead of asking while they
    had your attention?

    Now blithering idiots should go study before peppering you with inane
    questions, but that's a different situation (IMHO).

    We all have bad days...

    BTW, I benefitted from your answers, too.

    Thanks.

    MRW wrote:
    > I've been on Google searching for things for hours. I did not find
    > anything that would have led me to @@IDENTITY. So when he told me, I
    > simply asked if he had a quick example on how to use it while I've got
    > him.
    >
    >
    > Mark Rae wrote:
    > > "MRW" <> wrote in message
    > > news:...
    > >
    > > > Great! Thanks a lot!

    > >
    > > Sarat's comment about Google is very relevant, though... you really could
    > > have found this out for yourself in a matter of seconds...
    JT, Aug 21, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shiv
    Replies:
    0
    Views:
    398
  2. =?Utf-8?B?SnVzdGlu?=

    Updating multiple Tables

    =?Utf-8?B?SnVzdGlu?=, Nov 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,713
    Daniel Fisher\(lennybacon\)
    Nov 22, 2004
  3. updating multiple tables

    , Mar 21, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    5,217
    S. Justin Gengo
    Mar 21, 2006
  4. news.rcn.com
    Replies:
    2
    Views:
    1,093
    Roedy Green
    Dec 10, 2007
  5. Gancy
    Replies:
    4
    Views:
    160
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page