第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

必須聲明標(biāo)量變量@Id嗎?

必須聲明標(biāo)量變量@Id嗎?

HUWWW 2019-11-04 13:17:10
因此,我試圖從數(shù)據(jù)庫(kù)中獲取“客戶”,但出現(xiàn)異常System.Data.dll中發(fā)生類型'System.Data.SqlClient.SqlException'的異常,但未在用戶代碼中處理附加信息:必須聲明標(biāo)量變量"@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())                    {                        customer = new Customer();                        customer.Id = reader.GetInt32(reader.GetOrdinal("Id"));                        customer.FirstName = reader.GetString(reader.GetOrdinal("FirstName"));                        customer.LastName = reader.GetString(reader.GetOrdinal("LastName"));                        customer.Address = reader.GetString(reader.GetOrdinal("Address"));                    }                    command.ExecuteNonQuery();                    connection.Close();                }                return customer;            }        }    }using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.Text;using System.Threading.Tasks;
查看完整描述

2 回答

?
侃侃爾雅

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超16個(gè)贊

您應(yīng)該添加一個(gè)SqlParameter名稱@Id


command.CommandText = "SELECT * FROM CUSTOMER WHERE Id = @Id;";

command.Parameters.Add("@Id", SqlDbType.Int32).Value = Id;


查看完整回答
反對(duì) 回復(fù) 2019-11-04
  • 2 回答
  • 0 關(guān)注
  • 1797 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)