Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8424845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:07:00+00:00 2026-06-10T04:07:00+00:00

I have a model: public class KPIResults { public virtual string Title { get;

  • 0

I have a model:

public class KPIResults
{
   public virtual string Title { get; set; }
   public virtual int Total { get; set; }
   public virtual  int Week6 { get; set; }
   public virtual  int Week5 { get; set; }
   public virtual  int Week4 { get; set; }
   public virtual  int Week3 { get; set; }
   public virtual  int Week2 { get; set; }
   public virtual  int Week1 { get; set; }

   public virtual string stringWeek6 { get; set; }
   public virtual string stringWeek5 { get; set; }
   public virtual string stringWeek4 { get; set; }
   public virtual string stringWeek3 { get; set; }
   public virtual string stringWeek2 { get; set; }
   public virtual string stringWeek1 { get; set; }
}

In my reporting repository i have:

 int strfound = 0;
 string str = "Number";
 foreach (DataRow dr in dt.Rows)
 {
    string title = dr["Title"].ToString();
    int total = Convert.ToInt32(dr["Total"]);
    if (dr["Week6"].contains("Number")  //synntacs not right?
        var week6 = dr["strWeek6"]
    end

    or do this:
    strfound = str.IndexOf(dr);  //syntacs not right?
    if (strfound == 0)
    {
         var week6 = dr["strWeek6"]
    } 
    var week6 = Convert.ToInt32(dr["Week6"]);
    var week5 = Convert.ToInt32(dr["Week5"]);
    var week4 = Convert.ToInt32(dr["Week4"]);
    var week3 = Convert.ToInt32(dr["Week3"]);
    var week2 = Convert.ToInt32(dr["Week2"]);
    var week1 = Convert.ToInt32(dr["Week1"]);

    results.Add(new KPIResults() {Title = title, Total = total, Week6 = week6, Week5 = week5, Week4 = week4, Week3 = week3, Week2 = week2, Week1 = week1});

  }
  return results;

I should maybe try and do a string search but my code in the is is not right. I search for ways to handle string but not clear.

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:07:01+00:00Added an answer on June 10, 2026 at 4:07 am

    Somewhat unclear on what you are trying to do, to answer your question, All I want to know is it possible to cast the var type to be stored as an int or the other way around? No.

    I think your best bet would be to use string then it will be able to hold text and numbers. You could do a regex test to check if it contains text, then if not, convert the number it stores to an int for you to work this.

    Or just make a better model that will include all the sections you need.

    You could also use .GetType() to return the type of var.

    Update

    Ok, it looks like you are now trying to detect if dr["Week6"] contains a string or an int. One way to go about this is:

    int number;
    if(int.TryParse(dr["Week6"], out number))
        var week6 = dr["strWeek6"]
    

    If dr["Week6"] can be converted into an int, then the if statement is true and number will contain the value of dr["Week6"].

    Here is the metadata for int.TryParse:

    Summary:
    Converts the string representation of a number to its 32-bit signed integer
    equivalent. A return value indicates whether the conversion succeeded.

    Parameters: s:
    A string containing a number to convert.

    result:
    When this method returns, contains the 32-bit signed integer value equivalent
    to the number contained in s, if the conversion succeeded, or zero if the
    conversion failed. The conversion fails if the s parameter is null, is not
    of the correct format, or represents a number less than System.Int32.MinValue
    or greater than System.Int32.MaxValue. This parameter is passed uninitialized.

    Returns:
    true if s was converted successfully; otherwise, false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model public class Foo{ public int Id{get;set;} public string Name {get;
i have a model : public class person { public int id{get;set;} public string
I have model public class MyModel { public string Name { get; set;} }
I have: 1) public class Model { public String Name { get; set; }
Let's have a model public class Model { public int Number { get; set;
I have a view model - public class MyViewModel { public int id{get;set;}; Public
I have model: [Validator(typeof(RegisterValidator))] public class RegisterModel { public string Name { get; set;
I have a model: public class MyListModel { public int ID {get;set;} public List<User>
I have this model: public class Package { public string CustomerName { get; set;
I have a model public class Person { public string Name { get; set;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.