Hi!
my code gives me this error.
"An object reference is required for the non-static field, method, or property 'HD.RegisterMember.CN'"
Plz can anyone help me.
This is my code(Class);
private SqlConnection CN;
public static String getLastMemID()
{
String ID = null;
try
{
CN = new SqlConnection("Data Source=BJ-PC\\SQLEXPRESS;Initial Catalog=DB;Integrated Security=SSPI");
CN.Open();
string sqlQuery = @"SELECT MAX(Mem_ID) FROM MemberMaster";
using (SqlCommand com = new SqlCommand(sqlQuery, CN))
{
using (SqlDataReader dr = com.ExecuteReader())
{
if (dr.Read())
ID=dr[0].ToString();
}
}
}
catch (SqlException ex)
{
MessageBox.Show("A SqlException. You must check the Querry parameteres", "Error Message");
MessageBox.Show(ex.ToString());
}
finally
{
CN.Close();
}
// if (ID > 0)
// MessageBox.Show(ID);
// else
// MessageBox.Show("There is no id in this table (its an empty table)");
return ID;
}