我正在从事一个项目,而我遇到的问题是我想显示客户订单的历史记录。 我得到的错误是“关键字“内部”附近的“语法不正确” 我使用C#Windows Form和MSSQL
d2 = new SqlDataAdapter("Select
LastName,AFM,TYPE,CATEGORY,SalePrice,FPA,Quantity,Final_Price" +
"FROM CUSTOMER inner join(ORDER inner join PRODUCT_ORDER" +
"on ORDER.ID_ORDER = PRODUCT_ORDER.ID_ORDER inner join STORE on
PRODUCT_ORDER.K_E = STORE.KE)" +
"on CUSTOMER.CUST_ID = ORDER.CUST_ID WHERE LASTNAME='" +
comboBox1.Text.ToString()+ "'", connect);
ds2 = new DataSet();
b2 = new BindingSource();
d2.Fill(ds2);
DataTable dt = new DataTable();
dataGridView1.DataSource = ds2.Tables[0].DefaultView;
double sum = 0;
for(int i=0; i < dataGridView1.RowCount; i++)
{
double quantity =
Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value);
double fpa = Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value);
double SalePrice =
Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value);
sum = SalePrice * quantity * (fpa / 100);
}
label4.Text = Convert.ToString(sum);
答案 0 :(得分:0)
该查询看起来是由MS Access查询设计器生成的。风格很陈旧。
这可能更像是应该的:
string sql = "SELECT LastName, AFM, TYPE, CATEGORY, SalePrice, FPA, Quantity, Final_Price " +
"FROM CUSTOMER c " +
"INNER JOIN [ORDER] o ON c.CUST_ID = o.CUST_ID " +
"INNER JOIN PRODUCT_ORDER p ON o.ID_ORDER = p.ID_ORDER " +
"INNER JOIN STORE s ON p.K_E = s.KE " +
"WHERE c.LASTNAME =@LastName";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("", connect);
cmd.Parameters.AddWithValue("@LastName", ComboBox1.Text.Tostring());
System.Data.SqlClient.SqlDataAdapter d2 = new System.Data.SqlClient.SqlDataAdapter(cmd);
查询仍然需要工作。我将在select命令的字段上添加表限定符。处理完对象(或使用using)后,不要忘记丢弃对象