Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2006, 09:39 AM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help! Retrieving data from a formview!?!

Hi.
I am new at this and working with a web-project using Microsoft Visual Studio, and need some help quickly as I am stuck with a problem and I am running out of time. My project is making a web-based bookstore. I have made several pages, and on my start-page I have pictures of some of the books the store is selling. Under each book I have a button: <buy> and when the user clicks this button the book is supposed to be put in the shopping cart. The name of the book, the isbn and the price is retrieved from my database through a SQLDataSource, and is shown on the page in a FormView. My problem is writing the code that gets the title, isbn and price from the FormView and sends it to the shopping cart. I have a search page where I use a GridView, and the code I use there is like this:

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

        Dim row As GridViewRow
        Dim isbn As String
        Dim title As String
        Dim amount As Integer
        Dim price As Double
        Dim t As TextBox
        Dim p As Label
        Dim totalprice As Double

        row = GridView1.SelectedRow

        t = CType(row.Cells(8).Controls(1), TextBox)
        amount = CInt(t.Text)

        p = CType(row.Cells(3).Controls(1), Label)
        pris = CDbl(p.Text) * amount

        isbn = row.Cells(0).Text
        title = row.Cells(1).Text

        If amount = 0 Then
            Server.Transfer(isbn & ".aspx")
        Else
            Dim shoppingcart As New Data.DataTable
            shoppingcart = CType(Session("cart"), Data.DataTable)
            Dim newrow As Data.DataRow
            newrow = shoppingcart.NewRow
            newrow(0) = isbn
            newrow(1) = title
            newrow(2) = amount
            newrow(3) = price
            shoppingcart.Rows.Add(newrow)

            Session("cart") = shoppingcart
            totalprice = Session.Item("TotalPrice")
            totalprice = totalprice + price
            Session.Add("TotalPrice", totalprice)
            Server.Transfer("shoppingcart.aspx")
        End If
End sub

This code does the same thing as I wish to do with the FormView, my problem is finding the code that works for a FormView instead of a GridView. Can I use the same code, but just make some changes? And if so, what changes has to be made for this code to work with the FormView?

Live and learn!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving SQL statement from a FormView jcrabtreesla ASP.NET 2.0 Professional 0 August 11th, 2006 10:05 AM
Capture and emaio formview control data nuttylife2 ASP.NET 1.x and 2.0 Application Design 0 August 1st, 2006 11:44 AM
Retrieving Data From Server x_ray Word VBA 0 June 12th, 2006 10:33 AM
retrieving data using id. mikeuk Beginning PHP 7 July 21st, 2004 05:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.