troubleshooting Question

add new method to a class...

Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America asked on
ASP.NETC#.NET Programming
9 Comments1 Solution254 ViewsLast Modified:
In the following class, I have two methods:

1. public void ReadCriteria(string dataPoint)      <-- this one functions okay
2. public void UpdateCriteria(string dataPoint, string value, isInt as boolean)

The 2nd one is what I need to add to this class. Please note that UpdateCriteria() has different signature. The value to be updated for  dataPoint field is stored in value as string and isInt parameter indicate if the data type in the table is integer so we can cast it as int before updating it.

Question: Could you please help me to write UpdateCriteria() method?

Thank you.
public class RodCriteria
{
   public void UpdateCriteria(string dataPoint, string value, isInt as boolean)
    {

    public string ReadCriteria(string dataPoint)
    {
   //     string criteria = "";
   //     using (SqlConnection connection = new SqlConnection("Data Source=USER-PC;Initial Catalog=ROD_July18;Integrated Security=True"))
        {
   //         SqlCommand command = new SqlCommand();

   //         command.Connection = connection;
    //        command.CommandText = "SELECT Top 1 [" + dataPoint + "] From RodCtiteria";
    //        command.CommandType = CommandType.Text;

   //         connection.Open();
   //         SqlDataReader reader = command.ExecuteReader();
   //         if (reader.HasRows)
   //         {
   //             reader.Read();
   //             if (!reader.IsDBNull(0)) // instead of: reader.GetString(0) != ""
   //                 criteria = reader.GetString(0);
   //         }

   //         reader.Close();
   //     }
   //     return criteria;
    }

    public void ReadCriteria(string dataPoint)
    {

    public string ReadCriteria(string dataPoint)
    {
        string criteria = "";
        using (SqlConnection connection = new SqlConnection("Data Source=USER-PC;Initial Catalog=ROD_July18;Integrated Security=True"))
        {
            SqlCommand command = new SqlCommand();

            command.Connection = connection;
            command.CommandText = "SELECT Top 1 [" + dataPoint + "] From RodCtiteria";
            command.CommandType = CommandType.Text;

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            if (reader.HasRows)
            {
                reader.Read();
                if (!reader.IsDBNull(0)) // instead of: reader.GetString(0) != ""
                    criteria = reader.GetString(0);
            }

            reader.Close();
        }
        return criteria;
    }

    public RodCriteria()
    {
        //
        // TODO: Add constructor logic here
        //
    }
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros