SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Call a stored procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Shep
Starting Member

USA
19 Posts

Posted - 06/18/2013 :  15:08:42  Show Profile  Reply with Quote
Using VB and a Windows Form
I need to call a stored procedure named: validateUser

It is called by a button click and will put the info into a datatable.

Then I will use an "IF Statement" to validate that the Username and Password are valid.

If they ARE valid, then the user will be able to proceed to a Mainform
If they are NOT valid, then a Label will appear with "INVALID USERNAME/PASSWORD"

Any help will be appreciated.
Thanks
JS

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 06/18/2013 :  15:37:59  Show Profile  Reply with Quote
It is hard to tell what specifically you need help with. Especially hard because you never actually asked a question.

Do you have a vb development environment like visual studio?
Do you know how to create a windows forms project?
Do you know how to create a form with a button and associate some code with the OnClick event of the button?
Do you know how to use ADO.NET objects to connect to a sql server database and call a stored procedure?
Do you have Sql server management studio and can you create a stored procedure?
Do you already have a database with tables and data necessary to perform these validations?
etc...

There are plenty of tutorials out there for all this stuff - have you tried searching for any of them?
This forum is really for advice and/or code to solve specific problems. Not so much for providing complete solutions.




Be One with the Optimizer
TG
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3708 Posts

Posted - 06/18/2013 :  15:38:50  Show Profile  Reply with Quote
This is a standard problem that most of the frameworks including the .Net framework is set up for already. Google for "form-based authentication" and you will find lots of resources including sample code, tutorials etc. Some MSDN documentation here: http://support.microsoft.com/kb/301240
Go to Top of Page

Shep
Starting Member

USA
19 Posts

Posted - 06/18/2013 :  15:46:32  Show Profile  Reply with Quote
Sorry TG, I should have been more specific.

I am using Visual studio 2012 and sql server 2008R2.
The form is already created with the username and password textboxs and a submit button.

The stored procedure is:
@Username nvarchar(50), @Password nvarchar(50)
AS

SELECT *
FROM [User]
WHERE Username = @Username
AND [Password] = @Password

Its in Northwind database.
I already have a database connection

The tables are created and filled but only need to use the User table.

I DO NOT know how to connect to the database when the button is clicked and call the store procedure.

Once the info is passed in, I plan to write the IF statement to validate that the USERNAME/PASSWORD is valid.

This is what I need help with.

Thanks again
JS
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 06/18/2013 :  16:07:17  Show Profile  Reply with Quote
have a look at MSDN SqlCommand. There are some examples on this as well as on most of the methods. You'll need to decide if your procedure will return a result or not because you would call a different method depending.

usually simply double clicking the button in a designer window will create the OnClick event handler where you can put this code.

Be One with the Optimizer
TG
Go to Top of Page

Shep
Starting Member

USA
19 Posts

Posted - 06/19/2013 :  15:01:58  Show Profile  Reply with Quote
Here is the code that I ended up using(actual sql connection X'ed out):

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Create connection to database
Dim con As New SqlConnection("server=developmentdb1.xxxxxxxxxxx;database=Northwind;UID=NorthwindUser;PWD=NorthwindUser!;")
con.Open()

Dim command As SqlCommand = New SqlCommand("validateUser", con)
command.CommandType = CommandType.StoredProcedure

'add parameters
command.Parameters.AddWithValue("@Username", txtUsername.Text)
command.Parameters.AddWithValue("@Password", txtPassword.Text)

Dim result As Int32
result = CType(command.ExecuteScalar(), Int32)

If result = 1 Then

Main.Show()

Else
failLabel.Visible = True
End If


End Sub

I'm going to create a new thread similiar to this one about a similar code.


J.E.Shepler
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000