ASP.NET的request.queryString问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 04:32:28
string ptype = Request.QueryString["action"].ToString();
执行
Services.InsertProduct(ptype, ImageName, title, content);
Services类:
//添加product
public void insertProduct(string pro_name, string img, string content, string title)
{
string sql = "insert into product(pro_name,img,content,title) values ('" + pro_name + "','" + img + "','" + content + "','" + title + "')";
SQLHelper.ExecuteNonQuery(sql);
}
我想问的是Request.QueryString["action"]里的action为什么没有出现在pro_name列里面呢?这句话要传递的是什么参数呢?
呵呵,其实services类的完整内容是
Services.GetInstance().InsertProduct(ptype, string.Empty, title, content);
完整代码:
namespace BLL
{
public class Services
{
#region //单键模式
private static readonly object _synRoot = new object();
private static Se

既然添加了一条记录,但是字段pro_name为空,则有可能是string ptype = Request.QueryString["action"].ToString();没有取得值.
这样的参数都是通过url传递的,类似于addProduct.aspx?action=aaaaaaaaaa

这个代码有问题吧:
如果要执行Services.InsertProduct(ptype, ImageName, title, content); 这句的话的话
那么下面的函数的定义就有问题了
应该是定义成static类型的。因为上面是用的类直接调用该类的方法。所以说下面的Services类的public void insertProduct(string pro_name, string img, string content, string title) 方法定义不对。

如果程序照样能自信又不出错的话。
只能说Services.InsertProduct(ptype, ImageName, title, content); 他一定不是反问的Services类的public void insertProduct(string pro_name, string img, string content, string title) 方法了。

建议检查是有有同名覆盖的方法存在

然后就知道Request.QueryString["action"]里的action是否传入到相关方法里面了

string ptype = Request.QueryString["action"].ToString();
得到页面url参数action的值

学习来了,O(∩_∩)O~