I recently started teaching myself C#. Decided to try out a little project with some of the knowledge I have gained but I am now a bit stuck.
I am creating an activation class where it will connect to a db validate the code and then return if the code is valid or not.
This is the error I get and I understand why I get it but I dont know how to solve it:
"IndexOutOfRangeException. there is now row at position 0"
Here is the code"
Can someone please help me?
I am creating an activation class where it will connect to a db validate the code and then return if the code is valid or not.
This is the error I get and I understand why I get it but I dont know how to solve it:
"IndexOutOfRangeException. there is now row at position 0"
Here is the code"
Code:
class Activator2
{
public static string activate(string ActivationCode)
{
//Checks to see if the string ActivationCode is not null
if (ActivationCode.Length > 0)
{
System.Data.SqlClient.SqlConnection con;
DataSet dsl;
System.Data.SqlClient.SqlDataAdapter da;
con = new System.Data.SqlClient.SqlConnection();
dsl = new DataSet();
//Database Connection Configuration
con.ConnectionString = "Data Source=TERENCEVS-XP;Initial Catalog=Activator;Integrated Security=True";
//Open Connection
con.Open();
string sqlselect = "select ActivationCode from ActivationCodes where ActivationCode = '";
string singlequote = "'";
//Building select statement
string sql = sqlselect + ActivationCode + singlequote;
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
da.Fill(dsl, "ActivationCodes");
//Closing Conection
con.Close();
DataRow dRow = dsl.Tables["ActivationCodes"].Rows[0];
if (ActivationCode == dRow.ItemArray.GetValue(0).ToString())
{
return "1";
}
return "0";
}
return "No Activation Code Entered. Please enter a Code!";
Can someone please help me?