I want to enter details of a client into a database.If the details already exists the application must inform the user and they don't then save the details
here is my code
private void btnCreate_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString="Data Source=MyComputer\\SQLEXPRESS;Initial Catalog=TIP;Integrated Security=True;Pooling=False";
conn.Open();
string check = "SELECT COUNT(UserID)FROM Login WHERE UserID='"+txtID.Text+"'";
string input="INSERT INTO Login(UserID,UserName,Password,Station)VALUES('"+txtClientID.Text+"','"+txtClientName.Text+"','"+txtPass.Text+"','"+ClientRank.Text+"')";
SqlCommand cd = new SqlCommand(check, conn);
SqlCommand com = new SqlCommand(input, conn);
cd.CommandText = check;
SqlDataReader dr;
dr = cd.ExecuteReader();
if (dr.HasRows==false)
{
MessageBox.Show("UserID Already Assigned");
dr.Close();
Chidzima();
}
else if (dr.HasRows==true)
{
com.CommandText = input;
com.ExecuteNonQuery();
MessageBox.Show("Details Saved", "Valid Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
Chidzima();
}
else
{
}
conn.Close();
}
public void Chidzima()
{
txtID.Clear();
txtPass.Clear();
txtUser.Clear();
cmbSta.Text = "";
}
}
I am new to c# help me please!!