我从未尝试过这样的事情,所以我需要你的帮助。
我有以下代码:
public int AddChannel(NameValueCollection FormValues)
{
string Keys = string.Join(",",FormValues.AllKeys);
string Values = string.Join(",", FormValues.AllKeys.Select(key => String.Format("\"{0}\"", HttpContext.Current.Server.HtmlEncode(FormValues[key]))));
return InsertQuery("INSERT INTO channels (" + Keys + ") VALUES (" + Values + ");");
}
在处理时,某些字段应该是整数,否则mysql查询失败。 如何检查KeyValue并将其转换为正确的类型?
答案 0 :(得分:1)
简而言之,没有。来自http帖子的数据是文本。您可以尝试推断123
可能一个数字,但这不安全,因为"123"
是完全有效的字符串。就个人而言,我希望代码能够提前知道架构,或者访问架构。从架构中,应用正确的转换(然后通过相应类型的参数添加值)。