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

Discussion in 'ASP .Net' started by Kevin R, Sep 21, 2005.

  1. Kevin R

    Kevin R Guest

    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, Sep 21, 2005
    #1
    1. Advertising

  2. Kevin R

    David Browne Guest

    "Kevin R" <> wrote in message
    news:...
    > 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
     
    David Browne, Sep 21, 2005
    #2
    1. Advertising

  3. Kevin R

    Kevin R Guest

    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 > wrote in
    message news:%...
    >
    > "Kevin R" <> wrote in message
    > news:...
    >> 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
    >
     
    Kevin R, Sep 21, 2005
    #3
  4. Kevin R

    David Browne Guest

    "Kevin R" <> wrote in message
    news:...
    > 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
     
    David Browne, Sep 21, 2005
    #4
  5. Kevin R

    Kevin R Guest

    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 > wrote in
    message news:...
    >
    > "Kevin R" <> wrote in message
    > news:...
    >> 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
    >
    >
    >
    >
     
    Kevin R, Sep 21, 2005
    #5
  6. Kevin R

    Kevin R Guest

    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 > wrote in
    message news:...
    >
    > "Kevin R" <> wrote in message
    > news:...
    >> 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
    >
    >
    >
    >
     
    Kevin R, Sep 21, 2005
    #6
  7. Kevin R

    sumitha.v.r

    Joined:
    May 19, 2011
    Messages:
    1
    Location:
    Bangalore
    SQL Parameter error: "Name 'SqlDbType' is not declared"

    In C# :
    using System.Data;

    In VB.net :
    <%@ import Namespace ="System.Data" %>
     
    sumitha.v.r, May 19, 2011
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerome

    Name 'SqlDbType' is not declared?

    Jerome, Apr 27, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    1,598
    Jerome
    Apr 27, 2004
  2. Replies:
    4
    Views:
    548
    Matteo
    Mar 29, 2007
  3. Stuart Redmann
    Replies:
    5
    Views:
    527
    Stuart Redmann
    Dec 14, 2007
  4. ecoolone
    Replies:
    0
    Views:
    797
    ecoolone
    Jan 3, 2008
  5. Replies:
    5
    Views:
    661
Loading...

Share This Page