Ett exempel på hur man kan göra en inloggningsverifikation
public void LoggOn(string theUID, string thePWD)
{
try
{
// 1. Instantiate the connection
SqlConnection conn = new SqlConnection(@"server=.\SQLExpress;"
+ "database=spo12;" + "integrated Security=SSPI;");
SqlDataReader rdr = null;
try
{
string sqlQuery = "SELECT * "
+" FROM dbo.Users "
+" WHERE username = '" + theUID + "' AND pwd='" + thePWD + "'"
// 2. Open the connection
conn.Open();
// 3. Pass the connection to a command object
SqlCommand cmd = new SqlCommand(, conn);
// 4. Use the connection
// get query results
rdr = cmd.ExecuteReader();
if (rdr.HasRows) { }
}
catch (Exception myExeption)
{
MessageBox.Show("Huston!!\n We got problems\n" + myExeption.Message);
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if (conn != null)
{
conn.Close();
}
}
}