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

  • Home
  • SEARCH
  • 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 6717313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:50:13+00:00 2026-05-26T08:50:13+00:00

When I add a Car in my application I get The ConnectionString property has

  • 0

When I add a Car in my application I get

The ConnectionString property has not been initialized.

I have the problem of ConnectionString property. I check similar question of mine but I found nothing helpfulness.

I use a class connection named dbConnection.cs:

class dbConnection
{      
  //Connection to database 
  private string con = "Data Source=(local)\\SQLEXPRESS; Initial Catalog=MLQ7024; Integrated Security=TRUE".ToString();

  public string Con
  {
    get
    {
      return con;
    }
  }
}

This is the code of my button

private void btnAddCar_Click(object sender, EventArgs e)
{
  using (SqlConnection con = new SqlConnection(dc.Con))
  {
    DataTable dtCar = new DataTable();
    BindingSource Car_bs = new BindingSource();
    using (SqlCommand cmd = new SqlCommand("sp_Add_Car", con))
    {                  
      try
      {
        cmd.CommandType = CommandType.StoredProcedure;
        //......
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        dtCar.Clear();
        da.Fill(dtCar);
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message + "\t" + ex.Source);
      }
    }
  }

  refreshCar();            
}

This is the code of an another button working well without error

private void btnAddPayment_Click(object sender, EventArgs e)
{
  using (SqlConnection con = new SqlConnection(dc.Con))
  {
    DataTable dtPayment = new DataTable();
    using (SqlCommand cmd = new SqlCommand("sp_Add_Paiements", con))
    {
      try
      {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@id_paiement", SqlDbType.Char).Value = txtBoxPaymentId.Text;
        cmd.Parameters.Add("@montant", SqlDbType.SmallMoney).Value = txtBoxAmount.Text;
        cmd.Parameters.Add("@id_Location", SqlDbType.Char).Value = cmbpaymentLesaseId.Text;
        //cmd.Parameters.Add("@status", SqlDbType.Char).Value = txtBoxStatusPayment.Text;


         con.Open();
         cmd.ExecuteNonQuery();
         con.Close();
         dtPayment.Clear();
         da.Fill(dtPayment);

         btnAddLease.Hide();
         refreshPayments();
       }
       catch (Exception ex)
       {
         MessageBox.Show(ex.Message + "\t" + ex.Source);
       }
     }
   }
   btnAddPayment.Hide();
 }
  • 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-26T08:50:13+00:00Added an answer on May 26, 2026 at 8:50 am

    You aren’t showing where you have initialized your dbConnection class. Changing it all to static will probably help, I’m guessing:

    static class dbConnection
    {      
      //Connection to database 
      private static string con = "Data Source=(local)\\SQLEXPRESS; Initial Catalog=MLQ7024; Integrated Security=TRUE"
    
      public static string Con
      {
        get
        {
          return con;
        }
      }
    }
    

    If your dbConnection class worked in one method but not the other, chances are you had it initialized in one and not the other. Unless you have to deal with different database connections, using a static class for your database connections is probably the best route.

    Then you change your calling method like this:

    using (SqlConnection con = new SqlConnection(dbConnection.Con))
    {
      // blah-blah
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class : public class Car { public string Name { get;
Let's say I have a class; public class Car { public List<Passenger> Passengers {get;
hey, I've developped a car dock application. I can add shortcuts in my activity
I have been creating an QT application but struck in a place. I have
I have an ArrayList containing Car objects and I want to get from that
Intro: I am working on a Car dealer application so I have a table
List<Car> oUpdateCar = new List<Car>(); oUpdateCar.Add(new Car()); oUpdateCar[0].name = Color; oUpdateCar[0].value = red; oUpdateCar.Add(new
Add service reference to Amazon service fails, saying Could not load file or assembly
To add a whitespace seperator in a string we use String.Join(). My question:What(and how)
I add many check boxes to the excel sheet programaticaly using the following code:

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.