Question
The following code is throwing the following error message (C# Microsoft Visual Studio). Any help with what I am doing wrong with this code would
The following code is throwing the following error message (C# Microsoft Visual Studio). Any help with what I am doing wrong with this code would be appreciated:
Error: UnsuccessfulSytem.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'ON'.
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; using Acme.Data_Access_Layer; using Acme.Business_Layer;
namespace Acme { public partial class frmSalesView : Form { public frmSalesView() { InitializeComponent(); } private void DisplaySales() { string selectQuery;
selectQuery = "SELECT Sales.SalesID, Customers.CustomerID, Products.ProductID, Sales.Payable, "; selectQuery = selectQuery + "Sales.StartDate "; selectQuery = selectQuery + "FROM Sales INNER JOIN "; selectQuery = selectQuery + "Customers ON Sales.CustomerID = Customer.CustomerID,"; selectQuery = selectQuery + "Products ON Sales.ProductID = Products.ProductID"; selectQuery = selectQuery + " " + GlobalVariables.salesSearchCriteria;
SqlConnection conn = ConnectionManager.DatabaseConnection(); SqlDataReader rdr = null;
try { conn.Open(); SqlCommand cmd = new SqlCommand(selectQuery, conn); rdr = cmd.ExecuteReader(); while (rdr.Read()) { //Define the list items
Sales sales = new Sales(int.Parse(rdr["SalesID"].ToString()), int.Parse(rdr["CustomerID"].ToString()), int.Parse(rdr["ProductID"].ToString()), rdr["Payable"].ToString(), rdr["StartDate"].ToString()); ListViewItem lvi = new ListViewItem(sales.CustomerID.ToString()); lvi.SubItems.Add(sales.SalesID.ToString()); lvi.SubItems.Add(sales.CustomerID.ToString()); lvi.SubItems.Add(sales.ProductID.ToString()); lvi.SubItems.Add(sales.Payable); lvi.SubItems.Add(sales.StartDate); lvSales.Items.Add(lvi); } if (rdr != null) rdr.Close(); conn.Close(); } catch (Exception ex) { MessageBox.Show("Unsuccessful" + ex); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started