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

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
 
D

David Browne

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
 
K

Kevin R

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
 
D

David Browne

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
 
K

Kevin R

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
 
K

Kevin R

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
 
Joined
May 19, 2011
Messages
1
Reaction score
0
SQL Parameter error: "Name 'SqlDbType' is not declared"

In C# :
using System.Data;

In VB.net :
<%@ import Namespace ="System.Data" %>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top