This is the problem we are running into. With SQL server set up. We created a database, we also have SQL server set up at programming class in school. Every time we run the program, and type the user name and password, NOTHING happens when we click the button. We tried putting everything in a try/catch loop and output the exception. Nothing works, nothing happens. Nothing is being done. We just want the application to check if the username and password exists on the database, then show a different form. So thinking maybe it was just the school computers, I took the program home and installed Microsoft SQL server 2008 R2 on my local machine. The SAME thing happens. We have tried making new databases, played with the connection properties, fiddled with the security and permissions in the database. Added a data source connection in Visual Studio. We have tried almost everything. We really need help trying to understand why this wont work. Writing a simple counsel application to pull data from the North wind Database (Microsoft's example DB) it read data perfectly. Below, will be the code we are using in the Form itself. Any and all help will greatly be appreciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
namespace LoginForm
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
/// <summary>
/// Demonstrates how to work with SqlCommand objects
/// </summary>
private bool CompareStrings(string string1, string string2)
{
return String.Compare(string1, string2, true, System.Globalization.CultureInfo.InvariantCulture) == 0 ? true : false;
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
SqlConnection UGIcon = new SqlConnection();
UGIcon.ConnectionString = "Server=prog-2ua0210rw0\\programming; Database=myDB; User Id=sa; password=**************";
UGIcon.Open();
SqlCommand cmd = new SqlCommand("SELECT ISNULL(stUsername, '') AS stUsername, ISNULL(stPassword,'') AS stPassword, ISNULL(stRole,'') AS stRole FROM Users WHERE stUsername='" + textBoxUsername.Text + "' and stPassword='" + textBoxPassword.Text + "'", UGIcon);
SqlDataReader dr = cmd.ExecuteReader();
string userText = textBoxUsername.Text;
string passText = textBoxPassword.Text;
string stRole = "admin";
while (dr.Read())
{
if (this.CompareStrings(dr["stUsername"].ToString(), userText) &&
this.CompareStrings(dr["stPassword"].ToString(), passText) &&
this.CompareStrings(dr["stRole"].ToString(), stRole))
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Error");
}
}
dr.Close();
UGIcon.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
If it helps, we were trying to make a system kind of like what Valve does for steam where the little login form pops up. When we type the data into the text boxes, and press login. NOTHING AT ALL happens. Thank you again!

New Topic/Question
Reply




MultiQuote




|