没可访问的“New”接受此数目的参数,因此重载决策失败
没有可访问的“New”接受此数目的参数,因此重载决策失败
在做一个购物车的页面,要列出已购目录,这个是shoppingcart.aspx.vb里的代码,蓝色的那条代码下面始终是蓝色的波浪线,显示overload resolution failed because no accessible 'New' accepts this number of arguments
Partial Class shoppingcart
Inherits System.Web.UI.Page
Dim shortCartList As New ArrayList
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim Productname As String
Dim Productcode As String
Dim priceper As String
Productcode = Request.QueryString("code")
Productname = Request.QueryString("name")
priceper = Request.QueryString("price")
Dim productLine As Product
productLine = New Product(Productcode, Productname, CType(priceper, Double))
If Session.Item("sessionCart") Is Nothing Then
shortCartList = New ArrayList
Else
shortCartList = Session.Item("sessionCart")
End If
Dim tmpProduct As Product
Dim flag As Boolean
flag = True
If shortCartList.Count > 0 Then
For Each tmpProduct In shortCartList
If tmpProduct.code = productLine.code Then
flag = False
tmpProduct.changeQuantity(1)
End If
Next
End If
If flag Then
shortCartList.Add(productLine)
End If
Session("sessionCart") = shortCartList
End If
displayProduct()
End Sub
Protected Sub displayProduct()
GridView1.DataSource = shortCartList
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
End Sub
End Class
这个是app_code 里product.vb的代码
Imports Microsoft.VisualBasic
Public Class Product
Private Productcode As String
Private Productname As String
Private priceper As Double
Private Productquantity As Integer
Private Producttotal As Double
Public Property code As String
Get
Return Productcode
End Get
Set(ByVal value As String)
Productcode = code
End Set
End Property
Public Property name As String
Get
Return Productname
End Get
Set(ByVal code As String)
Productname = code
End Set
End Property
Public Property price As Double
Get
Return priceper
End Get
Set(ByVal code As Double)
priceper = code
End Set
End Property
Public Property quantity As Integer
Get
Return Productquantity
End Get
Set(ByVal code As Integer)
Productquantity = code
End Set
End Property
Public Property total As Double
Get
Return Producttotal
End Get
Set(ByVal code As Double)
Producttotal = code
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal code As String, ByVal price As Double)
Productcode = code
Productname = name
priceper = price
Productquantity = 1
Producttotal = Productquantity * priceper
End Sub
Public Function verify() As Boolean
If Productcode = "" Then
Return False
End If
If Productname = "" Then
Return False
End If
If priceper = "" Then
Return False
End If
Return True
End Function
Public Sub changeQuantity(ByVal quantity As Integer)
Productquantity = Productquantity + quantity
Producttotal = priceper * Productquantity
End Sub
End Class
------解决思路----------------------
在做一个购物车的页面,要列出已购目录,这个是shoppingcart.aspx.vb里的代码,蓝色的那条代码下面始终是蓝色的波浪线,显示overload resolution failed because no accessible 'New' accepts this number of arguments
Partial Class shoppingcart
Inherits System.Web.UI.Page
Dim shortCartList As New ArrayList
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim Productname As String
Dim Productcode As String
Dim priceper As String
Productcode = Request.QueryString("code")
Productname = Request.QueryString("name")
priceper = Request.QueryString("price")
Dim productLine As Product
productLine = New Product(Productcode, Productname, CType(priceper, Double))
If Session.Item("sessionCart") Is Nothing Then
shortCartList = New ArrayList
Else
shortCartList = Session.Item("sessionCart")
End If
Dim tmpProduct As Product
Dim flag As Boolean
flag = True
If shortCartList.Count > 0 Then
For Each tmpProduct In shortCartList
If tmpProduct.code = productLine.code Then
flag = False
tmpProduct.changeQuantity(1)
End If
Next
End If
If flag Then
shortCartList.Add(productLine)
End If
Session("sessionCart") = shortCartList
End If
displayProduct()
End Sub
Protected Sub displayProduct()
GridView1.DataSource = shortCartList
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
End Sub
End Class
这个是app_code 里product.vb的代码
Imports Microsoft.VisualBasic
Public Class Product
Private Productcode As String
Private Productname As String
Private priceper As Double
Private Productquantity As Integer
Private Producttotal As Double
Public Property code As String
Get
Return Productcode
End Get
Set(ByVal value As String)
Productcode = code
End Set
End Property
Public Property name As String
Get
Return Productname
End Get
Set(ByVal code As String)
Productname = code
End Set
End Property
Public Property price As Double
Get
Return priceper
End Get
Set(ByVal code As Double)
priceper = code
End Set
End Property
Public Property quantity As Integer
Get
Return Productquantity
End Get
Set(ByVal code As Integer)
Productquantity = code
End Set
End Property
Public Property total As Double
Get
Return Producttotal
End Get
Set(ByVal code As Double)
Producttotal = code
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal code As String, ByVal price As Double)
Productcode = code
Productname = name
priceper = price
Productquantity = 1
Producttotal = Productquantity * priceper
End Sub
Public Function verify() As Boolean
If Productcode = "" Then
Return False
End If
If Productname = "" Then
Return False
End If
If priceper = "" Then
Return False
End If
Return True
End Function
Public Sub changeQuantity(ByVal quantity As Integer)
Productquantity = Productquantity + quantity
Producttotal = priceper * Productquantity
End Sub
End Class
------解决思路----------------------
Public Sub New(ByVal code As String, ByVal price As Double)
这里要加一个参数才可以
Public Sub New(ByVal code As String,ByVal Productname as String, ByVal price As Double)