所以我试图从我的数据库中获取"客户",但我得到一个例外
System.Data.dll中出现"System.Data.SqlClient.SqlException"类型的异常,但未在用户代码中处理
附加信息:必须声明标量变量"@Id".
using Core;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseAccess
{
public class DbCustomer
{
private string ConnectionString = ConfigurationManager.ConnectionStrings["local"].ConnectionString;
private SqlConnection connection { get; set; }
public DbCustomer()
{
connection = new SqlConnection(ConnectionString);
}
public Customer GetCustomer(int Id)
{
Customer customer = null;
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM CUSTOMER WHERE Id = @Id;";
var reader = command.ExecuteReader();
while (reader.Read()) …Run Code Online (Sandbox Code Playgroud)