繁体   English   中英

尝试在浏览器中查看 Service.cs 并使用此活动时出错

[英]Error when trying to view the Service.cs in browser and using this activity

我总是收到这个错误:

没有为一个或多个必需参数指定值。

这是我的 C# 代码:

[WebMethod]
public string AddNews(string time1, string content,string topic)
{
    string strSql = String.Format("insert into [News] ([time],[content],[topic]) values (" + time1 + " , " + content + " , " + topic + " )");
    DAL.ChangeTable(strSql);
    return "News added Successfully";
}

先说第一件事。 此代码对 SQL 注入 ( https://en.wikipedia.org/wiki/SQL_injection ) 开放,不应使用。 其次,该消息表明您没有提供所需的输入。 我会检查是否有一个包含更多细节的内部异常。

使用SQL 参数

并在字符串中添加 '

string strSql = String.Format("INSERT INTO [News] ([time], [content], [topic]) VALUES ('" + time1 + "' , '" + content + "' , '" + topic + "' )");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM