CODE
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication6
{
public partial class Login :Form
{
public string g_Login;
int iCount;
Form1 frmMain = new Form1();
public Login()
{
InitializeComponent();
}
private void Login_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// string g_Login;
string ConString;
ConString = "Data Source=.;Initial Catalog=docworx;User ID=sa";
SqlConnection DbCon = new SqlConnection(ConString);
g_Login = this.txtUsername.Text;
String StrPassword = this.txtPassword.Text;
if (g_Login = null |= StrPassword = null)
{
MessageBox.Show("You are missing information. Please make sure that both the username and password fields are filled out.", "Missing Info");
this.txtUsername.Focus();
return;
}
String StrSql = "Select userid,password Form Login Where userid='" + g_Login + "'";
SqlCommand cm = new SqlCommand(StrSql, DbCon);
SqlDataReader dr;
Boolean valid = false;
Boolean HasRows = false;
try
{
DbCon.Open();
dr = cm.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
if (StrPassword == dr.Item("password"))
{
valid = true;
}
HasRows = true;
}
dr.Close();
}
catch (Exception exo)
{
MessageBox.Show(exo.Message);
}
finally
{
if (DbCon.State == ConnectionState.Open)
{
DbCon.Close();
}
cm = null;
dr = null;
DbCon.Dispose();
GC.Collect();
}
iCount = iCount + 1;
if (valid == true)
{
this.Hide();
frmMain.Show();
}
else
if (iCount == 3)
{
MessageBox.Show("Contact Safreak!", "Invalid Info");
this.Close();
}
else
if (HasRows == false)
{
MessageBox.Show("Invalid user name, try again!", "Invalid Info");
this.txtUsername.Focus();
this.txtUsername.Text = " ";
this.txtPassword.Text = " ";
}
else
{
MessageBox.Show("Invalid password, try again!", "Invalid Info");
this.txtPassword.Focus();
this.txtPassword.Text = " ";
}
}
}
}
im having these errors in my code:
Error 1 The type 'System.Data.SqlClient.SqlConnection' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.SqlClient.dll'
ERROR 2 it is not recognizing the item property of SqlDataReader