当我点击"查看账单"按钮时,我试图显示列表账单.但我有个例外
System.Data.SqlClient.SqlException:‘’附近的语法不正确‘,’. 必须声明标量变量"@Checkin".
这是我的代码
SQL个
ALTER PROC [dbo].[USP_GetListBillByDate]
@checkIn date, @checkOut date
AS
BEGIN
SELECT t.name , b.totalPrice , DateCheckIn,DateCheckOut
FROM dbo.Bill AS b, dbo.TableFood AS t
WHERE DateCheckIn >= @checkIn AND DateCheckOut <= @checkOut AND b.status = 1
AND t.id = b.idTable
END
BillDAO个
public DataTable GetBillListByDate(DateTime checkIn, DateTime checkOut)
{
return DataProvider.Instance.ExecuteQuery("exec USP_GetListBillByDate @checkIn,@checkOut", new object[] {checkIn, checkOut});
}
AdminManager个
void LoadDateTimePickerBill()
{
DateTime today = DateTime.Now;
dtpFromDate.Value = new DateTime(today.Year, today.Month, 1);
dtpToDate.Value = dtpFromDate.Value.AddMonths(1).AddDays(-1);
}
void LoadListBillByDate(DateTime checkIn, DateTime checkOut)
{
dgvBill.DataSource = BillDAO.Instance.GetBillListByDate(checkIn, checkOut);
}
private void btnViewBill_Click(object sender, EventArgs e)
{
LoadListBillByDate(dtpFromDate.Value, dtpToDate.Value);
}
DataProvider个
public DataTable ExecuteQuery(string query, object[] parameter = null)
{
DataTable data = new DataTable();
using (SqlConnection connection = new SqlConnection(connectionSTR))
{
connection.Open();
SqlCommand command = new SqlCommand(query, connection);
if (parameter != null)
{
string[] listPara = query.Split(' ');
int i = 0;
foreach (string item in listPara)
{
if (item.Contains('@'))
{
command.Parameters.AddWithValue(item, parameter[i]);
i++;
}
}
}
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(data);
connection.Close();
}
return data;
}
我试图研究和修复,但这个例外仍然存在.