Click here to Skip to main content
15,913,773 members
Home / Discussions / Database
   

Database

 
GeneralRe: DISTINCT values of Datatable columns??? Pin
mittalpa24-Aug-04 3:23
mittalpa24-Aug-04 3:23 
GeneralSmallDateTime and changing to DateTime Pin
Paul Watson23-Aug-04 7:37
sitebuilderPaul Watson23-Aug-04 7:37 
GeneralRe: SmallDateTime and changing to DateTime Pin
Colin Angus Mackay23-Aug-04 9:57
Colin Angus Mackay23-Aug-04 9:57 
GeneralRe: SmallDateTime and changing to DateTime Pin
Steven Campbell23-Aug-04 10:16
Steven Campbell23-Aug-04 10:16 
QuestionHow to retrieve data from stored function? Pin
Chodici Mrkev23-Aug-04 5:57
Chodici Mrkev23-Aug-04 5:57 
AnswerRe: How to retrieve data from stored function? Pin
Colin Angus Mackay23-Aug-04 6:15
Colin Angus Mackay23-Aug-04 6:15 
GeneralRe: How to retrieve data from stored function? Pin
Chodici Mrkev23-Aug-04 8:55
Chodici Mrkev23-Aug-04 8:55 
GeneralRe: How to retrieve data from stored function? Pin
Colin Angus Mackay23-Aug-04 9:54
Colin Angus Mackay23-Aug-04 9:54 
First, an optimisation tip. Although I'm thinking it may not be important in VB.NET as the ByVal and ByRef must be declared in method parameters - In C# classes are by reference by default and structures are by value by default. However, I still think the general rule is sound that a structure should always be small (no more than 16 bytes is one figure I've heard). So, for something like this a class would be better (in my opinion).

Looking at the structure you've given. I'm assuming that RecordId is the primary key of the table. If that is the case then UserName should have a unique constraint applied to it also to make sure that two users with the same UserName do not get inserted in the database.

Disclaimer: I've tried to write in VB.NET, which isn't my language - I've not done any VB since version 3, so please be aware that there may be errors in the syntax.

To get the data from the database create a stored procedure that is similar to this:
CREATE PROCEDURE GetUserDetails(@UserName varchar(64), @Password varchar(64))
AS
    -- This should always return zero or one records only.
    SELECT RecordId, Allowed, Name, Surname, Class, Email, UserName, Password, Skin, ImagePath
    FROM Users
    WHERE Username = @UserName
    AND Password = @Password
GO
Then in your .NET application some code like this:
Dim cmd As New SqlClient.SqlCommand("GetUserDetails", vilemConn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@Username", txtUsername.Text)
cmd.Parameters.Add("@Password", inputPassword1.Value)

' The data from the Select can be returned in to a DataSet or through a DataReader
' As you are populating your own structure it is probably better to use the DataReader
Dim dataReader As cmd.ExecuteDataReader()
Dim details As New UserData()
If dataReader.Read()
Then
    ' A record has returned from the Stored Procedure
    ' The numbers in the GetInt32 / GetString methods refer to 
    ' the position of the field. So, care must be taken to SELECT
    ' the fields in the same order in the stored procedure.
    details.strRecordId = dataReader.GetInt32(0)
    details.strAllowed= dataReader.GetInt32(1)
    details.strName = dataReader.GetString(2)
    details.strSurname = dataReader.GetString(3)
    details.strClass = dataReader.GetString(4)
    details.strEmail = dataReader.GetString(5)
    details.strUserName = dataReader.GetString(6)
    details.strPassword = dataReader.GetString(7)
    details.strSkin = dataReader.GetString(8)
    details.strImagePath = dataReader.GetString(9)
Else
    ' There is no record, therefore the user name and password don't match
    ' TODO: Put code here that will handle the failed login details.
End If


As this is quite a long reply... I'll continue in part two (Inserting the data) in a little while...


"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
Colin Angus Mackay23-Aug-04 11:09
Colin Angus Mackay23-Aug-04 11:09 
GeneralRe: How to retrieve data from stored function? Pin
Chodici Mrkev23-Aug-04 11:28
Chodici Mrkev23-Aug-04 11:28 
GeneralThanks Pin
Colin Angus Mackay23-Aug-04 11:45
Colin Angus Mackay23-Aug-04 11:45 
GeneralHandling of Fetched Records Pin
pry50422-Aug-04 21:47
pry50422-Aug-04 21:47 
GeneralRe: Handling of Fetched Records Pin
David Salter23-Aug-04 3:03
David Salter23-Aug-04 3:03 
GeneralRe: Handling of Fetched Records Pin
pry50423-Aug-04 4:38
pry50423-Aug-04 4:38 
GeneralCompiler Error Pin
#realJSOP22-Aug-04 12:33
professional#realJSOP22-Aug-04 12:33 
GeneralRe: Compiler Error Pin
S Sansanwal22-Aug-04 13:41
S Sansanwal22-Aug-04 13:41 
GeneralRe: Compiler Error Pin
#realJSOP22-Aug-04 23:33
professional#realJSOP22-Aug-04 23:33 
GeneralDatagrid data refresh problem Pin
lkreuzer22-Aug-04 7:17
lkreuzer22-Aug-04 7:17 
GeneralDataColumn question Pin
blankg22-Aug-04 6:47
blankg22-Aug-04 6:47 
GeneralADO + SQL statements Pin
#realJSOP22-Aug-04 6:01
professional#realJSOP22-Aug-04 6:01 
GeneralRe: ADO + SQL statements Pin
Christian Graus22-Aug-04 15:19
protectorChristian Graus22-Aug-04 15:19 
GeneralRe: ADO + SQL statements Pin
#realJSOP22-Aug-04 23:35
professional#realJSOP22-Aug-04 23:35 
GeneralRe: ADO + SQL statements Pin
Christian Graus23-Aug-04 10:23
protectorChristian Graus23-Aug-04 10:23 
GeneralRe: ADO + SQL statements Pin
Ryan Roberts23-Aug-04 4:44
Ryan Roberts23-Aug-04 4:44 
GeneralRe: ADO + SQL statements Pin
J. Vorstenbosch25-Aug-04 0:40
J. Vorstenbosch25-Aug-04 0:40 

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.