Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 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 September 21st, 2005, 08:45 AM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 CommandExecute example

The Chapter 9 CommandExecute.aspx example works fine using OleDB. Since I'll be writing most of my code against a sql database I'm trying to convert the code to work with northwind on my personal sql server database. I'm getting an error for the following line:

Code error:
Line 24: Dim firstNameParam As New SqlParameter("@FirstName", SqlDbType.VarChar, 10)

Error Message:
C:\Begining ASP.NET 1.1\ch09\CommandExecute.aspx(24) : error BC30451: Name 'SqlDbType' is not declared.

What am I doing wrong?

Thanks.

Kevin

My code:

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    ' Insert page code here
         '

         Sub btnRun_Click(sender As Object, e As EventArgs)
         Dim ConnectionString As String = "server=(local);database=northwind;trusted_connect ion=true"

         Dim dbConnection As New sqlConnection(connectionString)
         dbConnection.Open()

         Dim commandString As String = "INSERT INTO Employees(FirstName, LastName) " & _
             "Values(@FirstName, @LastName)"

         Dim dbCommand As New SqlCommand(commandString, dbConnection)


    '=============================


         Dim firstNameParam As New SqlParameter("@FirstName", SqlDbType.VarChar, 10)
         firstNameParam.Value = txtFirstName.Text
         dbCommand.Parameters.Add(firstNameParam)

         Dim lastNameParam As New SqlParameter("@LastName", SqlDbType.VarChar, 10)
         LastNameParam.Value = txtLastName.Text
         dbCommand.Parameters.Add(LastNameParam)

    '==============================

         dbCommand.ExecuteNonQuery()

         dbConnection.Close()
         End Sub


 
Old September 21st, 2005, 09:31 AM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good grief! It turned out to be simple. I needed to have the following import statements:

Original:
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data.SqlClient" %>

New:
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>


Kevin






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
chapter 7 - chapter 11 pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 3 January 6th, 2008 11:40 AM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





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