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 6135755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:31:02+00:00 2026-05-23T17:31:02+00:00

I am new to c# and Database linking that’s why not able to get

  • 0

I am new to c# and Database linking that’s why not able to get this by searching old posts of stackoverflow

Code like

private void issueDetails()
    {
        string connectionPath = @"Data Source=Data\libraryData.dat;Version=3;New=False;Compress=True";

        using (SQLiteConnection connection = new SQLiteConnection(connectionPath))
        {
            SQLiteCommand command = connection.CreateCommand();
            connection.Open();
            string query = "SELECT bookno as 'Book No.',studentId as 'Student ID',  title as 'Title', author as 'Author', description as 'Description', issuedDate as 'Issued Date', dueDate as 'Due Date' FROM issuedBooks";
            command.CommandText = query;
            command.ExecuteNonQuery();

            SQLiteDataAdapter da = new SQLiteDataAdapter(command);
            DataSet ds = new DataSet();
            da.Fill(ds, "issuedBooks");
            dataGridView1.DataSource = ds.Tables["issuedBooks"];
            dataGridView1.Sort(dataGridView1.Columns["Student ID"], ListSortDirection.Ascending);
            dataGridView1.ReadOnly = true;
            connection.Close();
        }
    }

i used like above for getting some library book details like issuedDate and dueDate, now i want highlight a particular cell that is over dueDate .

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        Color c = Color.Black;
        if (e.ColumnIndex == 6)
        {
            if (isLate(Convert.ToString(e.Value)))
            {
                c = Color.Red;
                count++;
                Console.WriteLine(count);
            }

        }
        e.CellStyle.ForeColor = c;
    }

    public string toInd(string date)
    {
        DateTimeFormatInfo fmt = new CultureInfo("fr-fr").DateTimeFormat;
        string dateString;
        DateTimeOffset offsetDate, dateig;
        string ret = DateTime.Now.ToShortDateString();
        dateString = date;
        bool ws = DateTimeOffset.TryParse(dateString, fmt, DateTimeStyles.None, out dateig);
        if (ws)
        {
            offsetDate = DateTimeOffset.Parse(dateString, fmt);
            ret = offsetDate.Date.ToShortDateString();
            return ret;
        }
        return ret;
    }

    private bool isLate(string nowS)
    {

        DateTime dueDate = Convert.ToDateTime(toInd(nowS));
        DateTime now;
        string present = DateTime.Now.ToShortDateString();
        now = Convert.ToDateTime(present);
        //Console.WriteLine(toInd(nowS));
        int a = dueDate.CompareTo(now);
        if (a >= 0)
            return false;
        else return true;
    }

but if use if (isLate(Convert.ToString(e.Value)))
{
c = Color.Red;
count++;
Console.WriteLine(count);
}
this for number of books over due, the ‘count’ value increases 4 time even only two books are over due in my database because this if block access 2 times while data binding and again two time when it sorts how can i get only number over due books value

  • 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-05-23T17:31:03+00:00Added an answer on May 23, 2026 at 5:31 pm

    Answer

    private void UpdateDataGridViewColor()
        {
            if (calledMethod == 2)
            {
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    int j = 6;
                    DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
                    CellStyle.ForeColor = Color.Red;
    
                    if (isLate(dataGridView1[j, i].Value.ToString()))
                    {
                        dataGridView1[j, i].Style = CellStyle;
                    }
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an old database, that i do not want to touch
We are designing a new database and I would like some input in where
I have an old database and a new database. The old records were converted
I created a new Entity Framework model from a database. This database has a
I'm designing a new DataBase that at the moment has 50 Tables. For many
I have a couple of POCO objects that look like this: public abstract class
IDbSetExtensions.AddOrUpdate is meant to help write code that works the same whether the database
I am building a multithreaded system that works like this: While there are entities:
I would like to populate various tables in my database after a new customer
I am trying to copy data from an old database into a new one,

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.