By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,120 Members | 1,786 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,120 IT Pros & Developers. It's quick & easy.

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

P: n/a
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_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

Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Kevin R" <ru******@darden.virginia.edu> wrote in message
news:eo**************@TK2MSFTNGP15.phx.gbl...
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_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

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
Nov 19 '05 #2

P: n/a
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


"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...

"Kevin R" <ru******@darden.virginia.edu> wrote in message
news:eo**************@TK2MSFTNGP15.phx.gbl...
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_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

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

Nov 19 '05 #3

P: n/a

"Kevin R" <ru******@darden.virginia.edu> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
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


Nov 19 '05 #4

P: n/a
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
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:eo**************@TK2MSFTNGP09.phx.gbl...

"Kevin R" <ru******@darden.virginia.edu> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #5

P: n/a
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
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:eo**************@TK2MSFTNGP09.phx.gbl...

"Kevin R" <ru******@darden.virginia.edu> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.