Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,661 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,173 people online right now. Registration is fast and FREE... Join Now!




SQL 2005 user input

 
Reply to this topicStart new topic

SQL 2005 user input, What is the charachter for waiting for user input

savybrie
post 13 Aug, 2008 - 11:05 AM
Post #1


D.I.C Head

**
Joined: 9 Aug, 2008
Posts: 74


My Contributions


Hello. I am trying to create a form in VB2008 that waits for a user to input their information. My SQL string looks something like this:

SELECT StudentID, StudentFName, StudentLName, StudentSecurityLevel, StudentGrade FROM StudentInfo WHERE StudentID LIKE '%'

I don't get anything returned even if I enter a specific Student ID that I know exists in the DB. Is there some other charachter or string I can use to get the user input in a form, take that and put into my query to get my results?
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 13 Aug, 2008 - 11:16 AM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


You're not getting any results because your database is trying to retrieve data for a UserID of %, which I imagine doesnt exist as a UserID. Using the LIKE keyword with wild card characters would be like this


sql

SELECT StudentID, StudentFName, StudentLName, StudentSecurityLevel, StudentGrade FROM StudentInfo WHERE StudentID LIKE '%' + 15


That would retrieve all information for all users who's UserID starts with 15 and ends with any number of digits. If you're wanting to retrieve user information for a specific user, say UserID 15, then dont use the LIKE keyword, use the equals sign, like


sql

SELECT StudentID, StudentFName, StudentLName, StudentSecurityLevel, StudentGrade FROM StudentInfo WHERE StudentID = 15


You could also put this into a stored procedure where you pass an INT data type parameter like


sql

CREATE PROCEDURE uspGetStudentInfo @SDtudentID INT
AS
SELECT
StudentID,
StudentFName,
StudentLName,
StudentSecurityLevel,
StudentGrade
FROM
StudentInfo
WHERE
StudentID = @StudentID


Here is some more information on the LIKE keyword and the wildcards characters that can be used with it.

Hope this answers your question? smile.gif
User is offlineProfile CardPM

Go to the top of the page

savybrie
post 13 Aug, 2008 - 11:25 AM
Post #3


D.I.C Head

**
Joined: 9 Aug, 2008
Posts: 74


My Contributions


Wow! That was an amazingly fast reply! Thank you!

Okay, so my next question is what does the @ sign do for you when you are creating your SQL statements?
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 13 Aug, 2008 - 11:46 AM
Post #4


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


The @ tells SQL Server that it is being passed a stored procedure parameter instead of a column name. It is used when creating stored procedures.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:39AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month