gpt4 book ai didi

c# - 将 Request.QueryString 转换为整数

转载 作者:太空狗 更新时间:2023-10-29 23:57:08 26 4
gpt4 key购买 nike

如何将 Request.Query 字符串转换为整数值。我已经尝试了所有的 Convert.ToInt32 和 Int32.Parse,但它说输入字符串的格式不正确。我使用字符串值作为存储过程的输入,该存储过程只接受该字段的整数类型。

这是部分代码-

string rid=Request.QueryString["RID"];
lblRID.Text = rid;
int id= Int32.Parse(rid);

if (lblRID.Text!= null)
SqlCommand myCommand = new SqlCommand("usp_NewResource_get", myConnection);
myCommand.Parameters.AddWithValue("@RID",id); //RID is int in database and stored procedure
myCommand.CommandType = CommandType.StoredProcedure;

最佳答案

int foo;
int.TryParse(Request.QueryString["foo"], out foo);

或者就像你说的,int.Parse 应该转换为 int

你能在这里发布一些代码吗?

关于c# - 将 Request.QueryString 转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/548877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com