SQL Parameter error: "Name 'SqlDbType' is not declared".

  • Thread starter Thread starter Kevin R
  • Start date Start date
K

Kevin R

I'm trying to update a sql database. It's modified Oledb code from an
example that did work with an access database. How can I tweak my code to
make it work?

Thanks in advance.

Kevin
======

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

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

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

Sub btnRun_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String =
"server=(local);database=northwind;trusted_connection=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
 
Kevin R said:
I'm trying to update a sql database. It's modified Oledb code from an
example that did work with an access database. How can I tweak my code to
make it work?

Thanks in advance.

Kevin
======

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

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

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

Sub btnRun_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String =
"server=(local);database=northwind;trusted_connection=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
Don't run inline script. Use a code-behind file and the IDE will assist you
in many ways.

For your particular problem, the full type name is

System.Data.SqlDbType

So either use the full name or import the System.Data namespace.

David
 
Thanks David. I just got it to work doing the following:

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" %>

I'm learning from a book that has us using the WebMatrix IDE. Unfortunately
it doesn't have the features of Visual Studio .NET!

Kevin
 
Kevin R said:
Thanks David. I just got it to work doing the following:

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" %>

I'm learning from a book that has us using the WebMatrix IDE.
Unfortunately it doesn't have the features of Visual Studio .NET!

If you are learning, consider using the next generation of tools.

Visual Web Developer 2005 Express Edition is the replacement for WebMatrix.

Visual Web Developer 2005 Express Edition Beta 2
http://lab.msdn.microsoft.com/express/vwd/default.aspx

David
 
Boy oh Boy... I have a Learning Tree Class comming up on ASP.NET 1.1 So
I'll have to cut my teeth on that first... The Visual Web Developer 2005
Express Edition looks very nice.

Kevin
 
Boy oh Boy... I have a Learning Tree Class comming up on ASP.NET 1.1 So
I'll have to cut my teeth on that first... The Visual Web Developer 2005
Express Edition looks very nice.

Kevin
 
Back
Top