 |
|
asp.net shopping cart โชว์โง่ครับทำไม่ได้ติดอะไรก็บอกไม่ถูกอ่ะครับรบกวนข้อความช่วยเหลือหน่อยครับ |
|
 |
|
|
 |
 |
|
เนื่องด้วยผมทำตามที่พี่วินตั้งไว้นะครับเเล้วผมได้แปลงการติดต่อฐานข้อมูลจากaccess เป็น sql ดู(แปลงโง่ๆ) เเล้วมันส่งค่าไม่ผ่านครับ
รบกวนท่านผู้รู้ตอบปัญหาผมหน่อยหรือท่านใดว่างช่วยแปลงเป็น sql ที่ถูกต้องให้ผมหน่อยนะครับ
Code (ASP)
Imports System.Data
Imports System.Data.SqlClient
Partial Class web_Default4
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BindData()
End Sub
Protected Sub BindData()
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim strConnString As String
strConnString = "Data Source=BENZNEW-PC;Initial Catalog=Project;Integrated Security=True"
objConn = New SqlConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM product "
Dim dtReader As SqlDataReader
objCmd = New SqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
myGridView.DataSource = dtReader
myGridView.DataBind()
dtReader.Close()
dtReader = Nothing
objConn.Close()
objConn = Nothing
End Sub
Protected Sub myGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles myGridView.RowCommand
Try
If e.CommandName = "Add2Cart" Then
Dim strProductID As String = e.CommandArgument
Dim dt As DataTable
Dim dr As DataRow
If IsNothing(Session("myCart")) Then
dt = New DataTable()
dt.Columns.Add("p_id")
dt.Columns.Add("qty")
' dt.Columns.Add("p_pic")
Session("myCart") = dt
End If
dt = DirectCast(Session("myCart"), DataTable)
Dim foundRows() As DataRow
foundRows = dt.Select("p_id = '" & strProductID & "'")
If foundRows.Length = 0 Then
dr = dt.NewRow()
dr("p_id") = strProductID
dr("qty") = 1
'dr("p_pic") = 1
dt.Rows.Add(dr)
Else
Dim updateRow() As DataRow
updateRow = dt.Select("p_id = '" & strProductID & "'")
updateRow(0)("qty") = updateRow(0)("qty") + 1
End If
Session("myCart") = dt
Response.Redirect("ViewCart.aspx")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Protected Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'*** Picture ***'
'Dim imgPicture As Image = DirectCast(e.Row.FindControl("imgPicture"), Image)
'If Not IsNothing(imgPicture) Then
' imgPicture.ImageUrl = "img/" & e.Row.DataItem("p_pic")
'End If
'*** ProductID ***'
Dim lblProductID As Label = DirectCast(e.Row.FindControl("lblProductID"), Label)
If Not IsNothing(lblProductID) Then
lblProductID.Text = e.Row.DataItem("p_id")
End If
'*** ProductName ***'
Dim lblProductName As Label = DirectCast(e.Row.FindControl("lblProductName"), Label)
If Not IsNothing(lblProductName) Then
lblProductName.Text = e.Row.DataItem("p_name")
End If
'*** Price ***'
Dim lblPrice As Label = DirectCast(e.Row.FindControl("lblPrice"), Label)
If Not IsNothing(lblPrice) Then
lblPrice.Text = e.Row.DataItem("p_price")
End If
'*** AddToCart ***'
Dim lnkAddToCart As LinkButton = DirectCast(e.Row.FindControl("lnkAddToCart"), LinkButton)
If Not IsNothing(lnkAddToCart) Then
lnkAddToCart.Text = "Add"
lnkAddToCart.CommandName = "Add2Cart"
lnkAddToCart.CommandArgument = e.Row.DataItem("p_id")
End If
End If
End Sub
End Class

มันฟ้องตามรูปโดยบรรทัดที่ฟ้องคือ
Code (VB.NET)
Response.Redirect("ViewCart.aspx")
ครับ
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET
|
|
 |
 |
 |
 |
Date :
2012-06-14 00:05:01 |
By :
benzdmax |
View :
1104 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูเเล้วเหมือนจะไม่เข้าครับผมไม่รุ้จะเเก้ยังไงเลยครับ อังกฤษก็ไม่แข็งด้วย แต่ลองๆทำเหมือนไม่มีค่าไปส่งไปอีกเพจ รบกวนพี่วินช่วยหน่อยนะครับ T T
|
 |
 |
 |
 |
Date :
2012-06-14 11:54:42 |
By :
benzdmax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณลองบน Event นี้แล้วสร้างใหม่ครับ โดยคลิกที่ Property ของ GridView รูปสายฟ้า มันมีให้สร้าง Event อยู่ครับ ค่อย ๆ ทำทีล่ะ Step ครับ จะได้เข้าใจและหา Error ไม่ยากครับ
|
 |
 |
 |
 |
Date :
2012-06-14 13:19:12 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับพี่วิน
|
 |
 |
 |
 |
Date :
2012-06-14 13:31:21 |
By :
benzdmax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลังจากที่หายไปนานเลยไปลองเขียนแบบนี้มาแทนครับแต่ติดที่มันขึ้นบบรทัดใหม่ไม่ได้รบกวนพี่ๆช่วยดูให้หน่อยนะครับCode (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Partial Public Class web_test
Inherits System.Web.UI.Page
Dim cons As String = Class1.Constr3
Dim DA As SqlDataAdapter
Dim DS As DataSet
Dim DT As DataTable
Dim DV As DataView
Dim com As SqlCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim Sql As String = "SELECT * FROM product ORDER BY ProductID"
Dim DA As New SqlDataAdapter(Sql, Cons)
Dim DS As New DataSet
DA.Fill(DS)
GridView1.DataSource = DS
GridView1.DataBind()
End If
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
' If e.CommandName = "Mylink" Then
'Label1.Text = "รหัสหมวดสินค้า :" & e.CommandArgument
'End If
Dim x() As String = Split(e.CommandArgument, ";")
If e.CommandName = "Mylink" Then
'Label1.Text = "รหัสหมวดสินค้า : " & x(0) & "</br>" & "ชื่อหมวดสินค้า : " & x(1)
End If
Dim sql As String = "Select ProductID,Productname,Price from product Where ProductID =" & x(0) & "Order by Productname"
Dim DA As New SqlDataAdapter(sql, cons)
Dim DS As New DataSet
Dim DR As DataRow
DA.Fill(DS)
'dr = DT.NewRow()
'DR("ProductID") = DS
'DR("ProductName") = DS
'DR("Price") = DS
' DR("ProductID") = 1
'DR = DT.NewRow()
'DT.Rows.Add(DR)
GridView2.DataSource = DS
GridView2.DataBind()
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim lnkAddToCart As LinkButton = DirectCast(e.Row.FindControl("เลือก"), LinkButton)
If Not IsNothing(lnkAddToCart) Then
lnkAddToCart.Text = "เลือก"
lnkAddToCart.CommandName = "Mylink"
lnkAddToCart.CommandArgument = e.Row.DataItem("ProductID")
End If
End Sub
End Class
|
 |
 |
 |
 |
Date :
2012-06-15 00:37:13 |
By :
benzdmax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังติดตรงไหนครับ 
|
 |
 |
 |
 |
Date :
2012-06-15 06:30:24 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ติดตรที่ว่าไม่รุ้จะใช้ตัวแปรไหนมาดึงให้มันขึ้นบรรทัดใหม่อ่ะครับพี่วิน
|
 |
 |
 |
 |
Date :
2012-06-15 08:33:27 |
By :
benzdmax |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|