Reputation: 1
I have a form in c# which get user and pass and a form that shows the informations of employees also two tables are in sql server which i want to show in Gridview.
private void button1_Click(object sender, EventArgs e)
{
String UserId = textBox1.Text;
String passwrd = textBox2.Text;
SqlConnection myConnection = new SqlConnection("Server=.,SQL2014;Database=MyTamrin;uid=Sa;password=Sa123;");
try
{
myConnection.Open();
}
catch (Exception r)
{
MessageBox.Show(r.ToString());
Console.WriteLine(r.ToString());
}
SqlCommand sqlcomm = new SqlCommand();
sqlcomm.CommandText = "SELECT count(*) FROM dbo.Empp WHERE fldUserName = @snum AND fldPassword = @pass";
sqlcomm.Parameters.AddWithValue("@snum", UserId);
sqlcomm.Parameters.AddWithValue("@pass", passwrd);
if ((Int16)sqlcomm.ExecuteScalar()==1)
{
Userinfo mainform = new Userinfo();
mainform.Show();
}
what is the problem?
Upvotes: 0
Views: 196
Reputation: 65534
You're not specifying the:
sqlComm.Connection = myConnection;
Upvotes: 1