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

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

調(diào)用存儲(chǔ)過程時(shí)出錯(cuò)返回值錯(cuò)誤數(shù)據(jù)類型 nvarchar(max) 為 int

調(diào)用存儲(chǔ)過程時(shí)出錯(cuò)返回值錯(cuò)誤數(shù)據(jù)類型 nvarchar(max) 為 int

C#
森林海 2023-07-22 18:35:40
我調(diào)用 astored procedure并且它有一個(gè)int返回值。但是,將值返回到我的后端時(shí)出現(xiàn)錯(cuò)誤。public async Task<string> CreatePortfolio(Portfolio portfolio){    string statusMessage;    using (SqlConnection conn = new SqlConnection(Connection))    {        SqlParameter returnValue = new SqlParameter(); //Holds the bit that determines if insert was successful or not        SqlCommand command;        command = new SqlCommand();        command.Connection = conn;        conn.Open();        command.CommandType = CommandType.StoredProcedure;        command.CommandText = "USP_Add_Portfolio";        command.Parameters.AddWithValue("@portfolioName", portfolio.PortfolioName);        command.Parameters.AddWithValue("@description", portfolio.Description);        command.Parameters.AddWithValue("@createID", portfolio.CreateID);        command.Parameters.AddWithValue("@updateID", portfolio.UpdateID);        command.Parameters.AddWithValue("@statusMessage", SqlDbType.NVarChar).Direction = ParameterDirection.Output;        returnValue.Direction = ParameterDirection.ReturnValue;        command.Parameters.Add(returnValue);        int i = await command.ExecuteNonQueryAsync().ConfigureAwait(false);        if(i == 1)        {            statusMessage = command.Parameters["@statusMessage"].Value.ToString();        }        else        {            statusMessage = "Error while adding please contact your administrator";        }    }    return statusMessage;}存儲(chǔ)過程完成并添加新記錄,但出現(xiàn)錯(cuò)誤int i = await command.ExecuteNonQueryAsync().ConfigureAwait(false);錯(cuò)誤:期待一個(gè) int 但得到 nvarchar
查看完整描述

2 回答

?
狐的傳說

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

ExecuteNonQuery(暫時(shí)不用擔(dān)心異步...)返回 UPDATE、INSERT、DELETE 影響的行數(shù),否則返回 -1。它不直接從存儲(chǔ)過程返回信息。

在上面的例子中,我認(rèn)為你應(yīng)該在沒有“int i ="的情況下調(diào)用“await”,而不用擔(dān)心調(diào)用的返回值ExecuteNonQueryAsync。相反,在該值之后,查看 中的值returnValue.Value,這將是“return”參數(shù)的值。它是一個(gè)對(duì)象,因此請(qǐng)驗(yàn)證類型或使用Convert.ToInt32().


查看完整回答
反對(duì) 回復(fù) 2023-07-22
?
函數(shù)式編程

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

這看起來不正確,因?yàn)?code>SqlDbType.NVarChar是一個(gè)枚舉值:

command.Parameters.AddWithValue("@statusMessage", SqlDbType.NVarChar).Direction = ParameterDirection.Output;

如果你改用這個(gè)會(huì)發(fā)生什么:

command.Parameters.Add(new SqlParameter("@statusMessage", SqlDbType.NVarChar, -1)).Direction = ParameterDirection.Output;


查看完整回答
反對(duì) 回復(fù) 2023-07-22
  • 2 回答
  • 0 關(guān)注
  • 167 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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