Windows Form Error: Invalid Cloumn Name Date in C#

Last Reply 4 months ago By Kirron

Posted 4 months ago

 Error iNVALID COLUMN NAME DATE

        public PrintBillsAll()
        {
            InitializeComponent();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
            {
                if (db.State == ConnectionState.Closed)
                    db.Open();
                string query = " Select Bill_No , Name, Address, MobileNo,Sl_No,ItemName,Size,Quantity,Rate,Amount,Total_Amount,Payment,Balance,Date" + 
                    "from SALES" + $" where Date between '{dtFromDate.Value}'  and '{ dtToDate.Value}'";
        
                billinginfoBindingSource.DataSource = db.Query<Billinginfo>(query, commandType: CommandType.Text);
            }
        }

 

Posted 4 months ago
Kirron says:
string query = " Select Bill_No , Name, Address, MobileNo,Sl_No,ItemName,Size,Quantity,Rate,Amount,Total_Amount,Payment,Balance,Date" +
                   "from SALES" + $" where Date between '{dtFromDate.Value}'  and '{ dtToDate.Value}'";

Try by below code also check the query string object value by debugging also be sure your table name SALES have date as a column in table.

string query = " Select Bill_No , Name, Address, MobileNo,Sl_No,ItemName,Size,Quantity,Rate,Amount,Total_Amount,Payment,Balance,Date" +
   "from SALES" + " where Date between '"+dtFromDate.Value+ "' and '"+ dtToDate.Value+"'"; 

 


Posted 4 months ago

Dear Kalpesh Thank you for your time.

 

I have fixed this error by simpling changing datetime picker property to short.