Click here to Skip to main content
15,798,111 members
Home / Discussions / Database
   

Database

 
GeneralSmallDateTime and changing to DateTime Pin
Paul Watson23-Aug-04 8:37
sitebuilderPaul Watson23-Aug-04 8:37 
GeneralRe: SmallDateTime and changing to DateTime Pin
Colin Angus Mackay23-Aug-04 10:57
Colin Angus Mackay23-Aug-04 10:57 
GeneralRe: SmallDateTime and changing to DateTime Pin
Steven Campbell23-Aug-04 11:16
Steven Campbell23-Aug-04 11:16 
QuestionHow to retrieve data from stored function? Pin
Chodici Mrkev23-Aug-04 6:57
Chodici Mrkev23-Aug-04 6:57 
AnswerRe: How to retrieve data from stored function? Pin
Colin Angus Mackay23-Aug-04 7:15
Colin Angus Mackay23-Aug-04 7:15 
GeneralRe: How to retrieve data from stored function? Pin
Chodici Mrkev23-Aug-04 9:55
Chodici Mrkev23-Aug-04 9:55 
GeneralRe: How to retrieve data from stored function? Pin
Colin Angus Mackay23-Aug-04 10:54
Colin Angus Mackay23-Aug-04 10:54 
GeneralRe: How to retrieve data from stored function? Pin
Colin Angus Mackay23-Aug-04 12:09
Colin Angus Mackay23-Aug-04 12:09 
Okay - Now for part two: Inserting the data

I've abbreviated the code here, because it gets a little repetative, you should get the idea.

Create a stored procedure like this:
CREATE PROCEDURE UpdateUserDetails(@RecordID int, @Allowed int, @Name varchar(64), @Surname varchar(64),
@Class varchar(64), @Email varchar(64), @Username varchar(64), @Password varchar(64),
@Skin varchar(64), @ImagePath varchar(64))
AS

-- Check to make sure the data exists already to be updated.
IF EXISTS(SELECT * FROM Users WHERE UserName = @UserName AND Password = @Password)
BEGIN
    -- Perform the update, all fields, except UserName and Password are updated here
    UPDATE Users
    SET Allowed = @Allowed, Name = @Name, Surname = @Surname -- and so on....
    WHERE UserName = @UserName AND Password = @Password
END
ELSE
BEGIN
    -- THere is no existing data to be updated, Raise and error - This will cause
    -- a SqlException to be thrown in the .NET Application.
    RAISERROR('The User does not exist', 16, 1);
    -- Alternatively, an INSERT could be performed here.
END
GO
In the .NET application you would write some code similar to this:
Dim cmd As New SqlClient.SqlCommand("UpdateUserDetails", vilemConn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@Username", details.strUserName)
cmd.Parameters.Add("@Password", details.strPassword)
' Keep adding parameters until all the parameters that the stored procedure takes are in.
' For consistency the parameters should be in the same order they appear in the stored procedure
' definition.


A final note. RecordId appears to be the Primary Key for the Users table. It is not a good idea to update that. It can cause all sorts of problems with Foreign Key relationships and depending on how you have your SQL Server set up it would most likely cause an error.

Does this help?


"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!


GeneralRe: How to retrieve data from stored function? Pin
Chodici Mrkev23-Aug-04 12:28
Chodici Mrkev23-Aug-04 12:28 
GeneralThanks Pin
Colin Angus Mackay23-Aug-04 12:45
Colin Angus Mackay23-Aug-04 12:45 
GeneralHandling of Fetched Records Pin
pry50422-Aug-04 22:47
pry50422-Aug-04 22:47 
GeneralRe: Handling of Fetched Records Pin
David Salter23-Aug-04 4:03
David Salter23-Aug-04 4:03 
GeneralRe: Handling of Fetched Records Pin
pry50423-Aug-04 5:38
pry50423-Aug-04 5:38 
GeneralCompiler Error Pin
#realJSOP22-Aug-04 13:33
mve#realJSOP22-Aug-04 13:33 
GeneralRe: Compiler Error Pin
S Sansanwal22-Aug-04 14:41
S Sansanwal22-Aug-04 14:41 
GeneralRe: Compiler Error Pin
#realJSOP23-Aug-04 0:33
mve#realJSOP23-Aug-04 0:33 
GeneralDatagrid data refresh problem Pin
lkreuzer22-Aug-04 8:17
lkreuzer22-Aug-04 8:17 
GeneralDataColumn question Pin
blankg22-Aug-04 7:47
blankg22-Aug-04 7:47 
GeneralADO + SQL statements Pin
#realJSOP22-Aug-04 7:01
mve#realJSOP22-Aug-04 7:01 
GeneralRe: ADO + SQL statements Pin
Christian Graus22-Aug-04 16:19
protectorChristian Graus22-Aug-04 16:19 
GeneralRe: ADO + SQL statements Pin
#realJSOP23-Aug-04 0:35
mve#realJSOP23-Aug-04 0:35 
GeneralRe: ADO + SQL statements Pin
Christian Graus23-Aug-04 11:23
protectorChristian Graus23-Aug-04 11:23 
GeneralRe: ADO + SQL statements Pin
Ryan Roberts23-Aug-04 5:44
Ryan Roberts23-Aug-04 5:44 
GeneralRe: ADO + SQL statements Pin
J. Vorstenbosch25-Aug-04 1:40
J. Vorstenbosch25-Aug-04 1:40 
GeneralAuto date colum Pin
Zee_Zee21-Aug-04 2:55
Zee_Zee21-Aug-04 2:55 

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.