Name 'SqlDbType' is not declared?

J

Jerome

Hi,

I keep getting the same compiler error: 'Name 'SqlDbType' is not
declared' and I don't know why?

I've declared the following:

<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@ import Namespace="System.Data." %>
<%@ import Namespace="System.Data.Sqlclient" %>
<%@ import Namespace="System.Data.SqlDbType" %>

What am I missing?

Any help would be greatly appreciated!

Jerome
 
M

Martin Dechev

Jerome,

There is no namespace System.Data.SqlDbType.

System.Data.SqlClient.SqlDbType is an enum and you can't use it with the
Import keyword.

Hope this helps
Martin
 
J

Jerome

Thanks Martin, but what could the reason be for that error message then?
Because even when removing the import keyword, it keeps getting displayed.

How do I declare that SqlDbType?

Thanks.
 
J

Jerome

Here's the line where the error comes:

cmdInsert.Parameters.Add( "@datedebut", SqlDbType.SmallDateTime
).Value=datedebut.Text )

Perhaps that'll help?
 
M

Martin Dechev

For this exact error try:

cmdInsert.Parameters.Add( _
"@datedebut", _
System.Data.SqlClient.SqlDbType.SmallDateTime).Value = _
DateTime.Parse(datedebut.Text)

Or some other overload of the static Parse method, or the static ParseExact
method on the DateTime structure, depending on the input.

Hope this helps
Martin
 
J

Jerome

Thanks Martin, but now I get the following:

Compiler Error Message: BC30456: 'SqlDbType' is not a member of 'SqlClient'.

I really don't quite get it because: cmdInsert.Parameters.Add(
"@datedebut", SqlDbType.SmallDateTime).Value=datedebut.Text is the
adaptation of an example from an asp.net book! They only difference is
in the example it was SqlDbType.Money that was used...

I'm trying to find out some more.
 
M

Martin Dechev

Sorry, it was my mistake, SqlDbType is in fact in the System.Data namespace,
not in System.Data.SqlClient.

If datedebut.Text is "27/04/2004 15:30:00" the following should work:

cmdInsert.Parameters.Add( _
"@datedebut", _
System.Data.SqlClient.SqlDbType.SmallDateTime).Value = _
DateTime.ParseExact(datedebut.Text, _
"dd/MM/yyyy HH:mm:ss", _
System.Globalization.DateTimeFormatInfo.InvariantInfo)

Greetings
Martin
 
M

Martin Dechev

Martin Dechev said:
Sorry, it was my mistake, SqlDbType is in fact in the System.Data namespace,
not in System.Data.SqlClient.

If datedebut.Text is "27/04/2004 15:30:00" the following should work:

cmdInsert.Parameters.Add( _
"@datedebut", _
System.Data.SqlClient.SqlDbType.SmallDateTime).Value = _
DateTime.ParseExact(datedebut.Text, _
"dd/MM/yyyy HH:mm:ss", _
System.Globalization.DateTimeFormatInfo.InvariantInfo)

And I should stop copy-pasting wrong code....

cmdInsert.Parameters.Add( _
"@datedebut", _
System.Data.SqlDbType.SmallDateTime).Value = _
DateTime.ParseExact(datedebut.Text, _
"dd/MM/yyyy HH:mm:ss", _
System.Globalization.DateTimeFormatInfo.InvariantInfo)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top