Click here to Skip to main content
15,905,419 members
Home / Discussions / Database
   

Database

 
AnswerRe: Sql Query Pin
Mycroft Holmes17-Sep-13 12:57
professionalMycroft Holmes17-Sep-13 12:57 
Questionhow to check available cleaner Pin
Jassim Rahma16-Sep-13 9:28
Jassim Rahma16-Sep-13 9:28 
AnswerRe: check the end time also Pin
David Mujica16-Sep-13 9:43
David Mujica16-Sep-13 9:43 
GeneralRe: check the end time also Pin
Jassim Rahma16-Sep-13 9:46
Jassim Rahma16-Sep-13 9:46 
GeneralRe: check the end time also Pin
David Mujica16-Sep-13 10:03
David Mujica16-Sep-13 10:03 
GeneralRe: check the end time also Pin
Jassim Rahma30-Sep-13 23:03
Jassim Rahma30-Sep-13 23:03 
SuggestionRe: how to check available cleaner Pin
Richard Deeming16-Sep-13 10:58
mveRichard Deeming16-Sep-13 10:58 
QuestionTable UserId row population Pin
Member 914293616-Sep-13 9:21
Member 914293616-Sep-13 9:21 
Hi there,

I am fairly new to programming SP, I am trying to create a relationship between to tables in my database. The tables are aspnet_Membership and aspnet_Genealogy, I have setup a relation with the two tables using a PK in the table aspnet_Membership and a FK in the table aspnet_Genealogy as can be seen in the code below:

SQL
CREATE TABLE [dbo].[aspnet_Genealogy] (
    [GenealogyId]       INT              IDENTITY (1, 1) NOT NULL,
    [UserId]            UNIQUEIDENTIFIER NULL,
    [FamilyName]        CHAR (200)       NOT NULL,
    [FirstName]         CHAR (200)       NULL,
    [MiddleName1]       CHAR (200)       NULL,
    [MiddleName2]       CHAR (200)       NULL,
    [MiddleName3]       CHAR (200)       NULL,
    [Gender]            CHAR (10)        NULL,
    [DOB]               VARCHAR (20)     NOT NULL,
    [COB]               CHAR (200)       NULL,
    [SOB]               CHAR (200)       NULL,
    [COOB]              CHAR (200)       NULL,
    [Newsletter]        CHAR (10)        NULL,
    [DateTimeGenealogy] DATETIME         NOT NULL,
    PRIMARY KEY CLUSTERED ([GenealogyId] ASC),
    CONSTRAINT [FK_aspnet_Genealogy_aspnet_Membership] FOREIGN KEY ([UserId]) REFERENCES [dbo].[aspnet_Membership] ([UserId])
);


and

SQL
CREATE TABLE [dbo].[aspnet_Membership] (
    [ApplicationId]                          UNIQUEIDENTIFIER NOT NULL,
    [UserId]                                 UNIQUEIDENTIFIER NOT NULL,
    [Password]                               NVARCHAR (128)   NOT NULL,
    [PasswordFormat]                         INT              DEFAULT ((0)) NOT NULL,
    [PasswordSalt]                           NVARCHAR (128)   NOT NULL,
    [MobilePIN]                              NVARCHAR (16)    NULL,
    [Email]                                  NVARCHAR (256)   NULL,
    [LoweredEmail]                           NVARCHAR (256)   NULL,
    [PasswordQuestion]                       NVARCHAR (256)   NULL,
    [PasswordAnswer]                         NVARCHAR (128)   NULL,
    [IsApproved]                             BIT              NOT NULL,
    [IsLockedOut]                            BIT              NOT NULL,
    [CreateDate]                             DATETIME         NOT NULL,
    [LastLoginDate]                          DATETIME         NOT NULL,
    [LastPasswordChangedDate]                DATETIME         NOT NULL,
    [LastLockoutDate]                        DATETIME         NOT NULL,
    [FailedPasswordAttemptCount]             INT              NOT NULL,
    [FailedPasswordAttemptWindowStart]       DATETIME         NOT NULL,
    [FailedPasswordAnswerAttemptCount]       INT              NOT NULL,
    [FailedPasswordAnswerAttemptWindowStart] DATETIME         NOT NULL,
    [Comment]                                NTEXT            NULL,
    PRIMARY KEY NONCLUSTERED ([UserId] ASC),
    FOREIGN KEY ([ApplicationId]) REFERENCES [dbo].[aspnet_Applications] ([ApplicationId]),
    FOREIGN KEY ([UserId]) REFERENCES [dbo].[aspnet_Users] ([UserId])
);


GO
EXECUTE sp_tableoption @TableNamePattern = N'[dbo].[aspnet_Membership]', @OptionName = N'text in row', @OptionValue = N'3000';


GO
CREATE CLUSTERED INDEX [aspnet_Membership_index]
    ON [dbo].[aspnet_Membership]([ApplicationId] ASC, [LoweredEmail] ASC);


The SP code is for aspnet_Add_Genealogy is as follows below:

SQL
CREATE PROCEDURE [dbo].[aspnet_AddGenealogy]
(
	@FamilyName char(200),
	@FirstName char(200),
	@MiddleName1 char(200),
	@MiddleName2 char(200),
	@MiddleName3 char(200),
	@Gender char(10),
	@DOB varchar(20),
	@COB char(200),
	@SOB char(200),
	@COOB char(200),
	@Newsletter char(200),
	@DateTimeGenealogy DateTime
)
	
AS
BEGIN
 
	INSERT INTO aspnet_Genealogy (FamilyName, FirstName, MiddleName1, MiddleName2, MiddleName3, Gender, DOB, COB, SOB, COOB, Newsletter, DateTimeGenealogy)
	VALUES (@FamilyName, @FirstName, @MiddleName1, @MiddleName2, @MiddleName3, @Gender, @DOB, @COB, @SOB, @COOB, @Newsletter, @DateTimeGenealogy)

	DECLARE @UserId uniqueidentifier
	DECLARE @GenealogyId int

IF ( @GenealogyId = +1 )

        UPDATE   dbo.aspnet_Genealogy
        SET      UserId = @UserId
        FROM     dbo.aspnet_Membership u, aspnet_Genealogy m
        WHERE    @UserId = u.UserId AND @UserId = m.UserId

        IF ( @@ROWCOUNT = 0 ) -- User ID not found
            RETURN -1
    END

    SELECT  m.UserId, m.FamilyName, m.FirstName, m.MiddleName1, m.MiddleName2, m.MiddleName3, m.Gender, m.DOB, m.COB, m.SOB, m.COOB, m.Newsletter, m.DateTimeGenealogy, u.UserId
    FROM    dbo.aspnet_Membership u, dbo.aspnet_Genealogy m
    WHERE   @UserId = u.UserId AND u.UserId = m.UserId

    IF ( @@ROWCOUNT = 0 ) -- User ID not found
       RETURN -1

    RETURN 0


I have setup a SP with INSERT and SETUP, SELECT instructions as can be seen above, I know it is probably something small I am missing. The UserId did not join with aspnet_genealogy table.

I did the inner join in a view, vw_aspnet_Genealogy, the code is below:

SQL
CREATE VIEW [dbo].[vw_aspnet_Genealogy]
	AS SELECT [dbo].[aspnet_Genealogy].[UserId], [FamilyName], [dbo].[aspnet_Genealogy].[FirstName], [dbo].[aspnet_Genealogy].[MiddleName1], [dbo].[aspnet_Genealogy].[MiddleName2], [dbo].[aspnet_Genealogy].[MiddleName3], [dbo].[aspnet_Genealogy].[Gender], [dbo].[aspnet_Genealogy].[DOB], [dbo].[aspnet_Genealogy].[COB], [dbo].[aspnet_Genealogy].[SOB], [dbo].[aspnet_Genealogy].[COOB], [dbo].[aspnet_Genealogy].[Newsletter], [dbo].[aspnet_Genealogy].[DateTimeGenealogy] FROM [dbo].[aspnet_Membership] INNER JOIN [dbo].[aspnet_Genealogy]
      ON [dbo].[aspnet_Membership].[UserId] = [dbo].[aspnet_Genealogy].[UserId]


I set a aspx webpage with a gridview and configure the gridview to use the view as its table source. I trying have the UserId data show up in the gridview from the aspnet_Member table into the aspnet_Genealogy table. Can anyone help?

Thanks

Anthony
AnswerRe: Table UserId row population Pin
Mycroft Holmes16-Sep-13 12:48
professionalMycroft Holmes16-Sep-13 12:48 
GeneralRe: Table UserId row population Pin
Member 914293616-Sep-13 15:08
Member 914293616-Sep-13 15:08 
QuestionMySQL - Can't create Visit table Pin
noislude15-Sep-13 4:42
noislude15-Sep-13 4:42 
AnswerRe: MySQL - Can't create Visit table Pin
PIEBALDconsult15-Sep-13 5:54
mvePIEBALDconsult15-Sep-13 5:54 
GeneralRe: MySQL - Can't create Visit table Pin
noislude15-Sep-13 6:15
noislude15-Sep-13 6:15 
GeneralRe: MySQL - Can't create Visit table Pin
Mycroft Holmes15-Sep-13 12:56
professionalMycroft Holmes15-Sep-13 12:56 
GeneralRe: MySQL - Can't create Visit table Pin
noislude15-Sep-13 13:01
noislude15-Sep-13 13:01 
GeneralRe: MySQL - Can't create Visit table Pin
Eddy Vluggen16-Sep-13 2:59
professionalEddy Vluggen16-Sep-13 2:59 
AnswerRe: MySQL - Can't create Visit table Pin
Bernhard Hiller16-Sep-13 2:23
Bernhard Hiller16-Sep-13 2:23 
AnswerRe: MySQL - Can't create Visit table Pin
Richard Deeming16-Sep-13 2:25
mveRichard Deeming16-Sep-13 2:25 
QuestionSQL Query Help! Pin
Member 1026694314-Sep-13 16:33
Member 1026694314-Sep-13 16:33 
AnswerRe: SQL Query Help! Pin
PIEBALDconsult14-Sep-13 17:39
mvePIEBALDconsult14-Sep-13 17:39 
AnswerRe: SQL Query Help! Pin
Eddy Vluggen15-Sep-13 2:02
professionalEddy Vluggen15-Sep-13 2:02 
AnswerRe: SQL Query Help! Pin
RedDk15-Sep-13 12:08
RedDk15-Sep-13 12:08 
AnswerRe: SQL Query Help! Pin
Malte Klena16-Sep-13 1:55
Malte Klena16-Sep-13 1:55 
QuestionHelp Me Pin
Member 1025981112-Sep-13 23:58
professionalMember 1025981112-Sep-13 23:58 
AnswerRe: Help Me Pin
Richard MacCutchan12-Sep-13 23:58
mveRichard MacCutchan12-Sep-13 23:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.