Problema risolto ragazzi ho provato con un altro codice migliore
codice:
string username = txtUserName.Text;
string password = txtPassword.Text;
if (ValidateUserNamePassword(username, password))
{
// move to next form or do whatever you need to do after a successfull login
}
else
{
MessageBox.Show("Invalid user name or password", "Invalid Login");
return;
}
ed ecco qua
codice:
public bool ValidateUserNamePassword(string _username, string _password)
{
string connectionString = "Data Source=[servername];Initial Catalog=[databaseName];User ID=[Admin Login];Password=[Admin Password];";
using (SqlConnection cn = new SqlConnection(connectionString);
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "tsp_GetUserNameAndPassword";
SqlParameterCollection sqlParams = cmd.Parameters;
sqlParams.AddWithValue("@UserName", _username);
sqlParams.AddWithValue("@Password", _password);
cn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
if (dr.Read())
{
// this will return true if a row matching the username and password is found.
// this means that the user's input is valid
return true;
}
else
{
return false;
}
dr.close();
cn.close();
}
}
e per finire
codice:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[tsp_GetUserNameAndPassword]
@UserName varchar(15) -- or whatever the datatype is
@Password varchar(25) -- or whatever the datatype is
AS
SELECT
UserName
, Password
FROM [TableName]
WHERE
UserName = @UserName
Password = @Password
pero non ho capito la 2 e 3 parte dove vanno???