Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

This is probably a very simple problem but i would appreciate some help.

 

I have wired up a datagrid button with the following code.

 

Sub AddProduct(sender As Object, e As DataGridCommandEventArgs)

Dim ProductID As Integer = CType(dg.DataKeys(e.Item.ItemIndex), Integer)

' Create the connection object

Dim connection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))

' Create and initialize the command object

Dim command As New SqlCommand("SP_AddToCart", connection)

command.CommandType = CommandType.StoredProcedure.........................

 

This code works fine on the page

 

 

I am trying to compile a public shared function using the following

 

Imports System

Imports System.Data

ImportS System.Data.SqlClient

Imports System.configuration

Imports System.Web

 

Namespace worldshop

Public Class ShoppingCart

 

Public Shared Function AddProduct(sender As Object, e As DataGridCommandEventArgs)

Dim ProductID As Integer = CType(dg.DataKeys(e.Item.ItemIndex), Integer) ' Create the connection object

Dim connection As New SqlConnection(connectionString)

' Create and initialize the command object

Dim command As New SqlCommand("SP_AddToCart", connection)

command.CommandType = CommandType.StoredProcedure

 

But i get the the following error:

 

Public Shared Function AddProduct(sender As Object, e As DataGridCommandEven

tArgs) ~~~~~~~~~~~~~~~~~~~~~~~~

C:\worldshopdevelopement\ShoppingCart.vb(53) : error BC30451: ?? 'dg' ??????????

? Dim ProductID As Integer = CType(dg.DataKeys(e.Item.ItemIndex), Integer)

 

Can anyone tell me where i am going wrong

 

Many thanks

 

Martin

Posted
BC30451 means a variable you are using is not declared. The line number will give you a reference. If you use Option Strict you'll see this error before you compile it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...