I wrote a test program to create a database.
Here is the program:
Imports System
Imports System.Data.SqlServerCe
Imports System.Data.Common
Imports System.Data
Imports System.IO
Imports System.IO.Directory
Imports System.Configuration
Imports System.Reflection

Public Class create_DB

Public SQLEngine As SqlServerCe.SqlCeEngine
Public dir As String
Public SQL As String
Dim connString As String
Dim msg As String
Dim connCE As SqlCeConnection
Dim comnd As SqlCeCommand


Public Sub New()
Try
dir = "\db.sdf"

Catch ex As Exception

MsgBox(ex.ToString())
Return
End Try

Try
If File.Exists(dir) Then
File.Delete(dir)
End If
Catch ex As Exception
MsgBox(dir)
Return
End Try
Try
connString = "data source=" & dir
SQLEngine = New SqlServerCe.SqlCeEngine(connString)
SQLEngine.CreateDatabase()

REM Create an SQL command to create A TABLE

SQL = "CREATE TABLE MAIN_INFO ( "
SQL &= "main_key CHAR(40) PRIMARY KEY, "
SQL &= "memo_data ntext "
SQL &= ") ;"


Catch ex As Exception
msg = "create DB"
MsgBox(ex.ToString(), , msg)
Return
End Try

Try
connCE = New SqlCeConnection(connString)
connCE.Open()
Catch ex As Exception
msg = "Connection:"
MsgBox(ex.ToString(), , msg)

End Try

comnd = New SqlCeCommand

Try
comnd.Connection = connCE
comnd.CommandText = SQL
MsgBox(SQL)

MsgBox("before execute")
comnd.ExecuteNonQuery()
Catch ex As SqlCeException
MsgBox(ex.Message, , "Message")
msg = "Execute SQL: "
MsgBox(ex.ToString(), , msg)

Catch ex As Exception
msg = "Execute SQL: "
MsgBox(ex.ToString(), , msg)
End Try


End Sub

End Class

After executing the statement "comnd.ExecuteNonQuery()" I am getting
"The specified data type is not valid.[Data type,,,,,]

System.Data.SQLServerCE.SQLCeExeption".

Any idea which data type in not valid?

Thanks,

Zalek

Re: Newbie - SQLCE exception. by Yosh

Yosh
Fri Oct 07 23:55:49 CDT 2005

Check out the valid datatypes for SQLCE

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqlce/htm/_lce_data_types.asp


"Zalek Bloom" <ZalekBloom@hotmail.com> wrote in message
news:k79ek1hr3sok9mhs52vnmmk0p3l340r637@4ax.com...
>I wrote a test program to create a database.
> Here is the program:
> Imports System
> Imports System.Data.SqlServerCe
> Imports System.Data.Common
> Imports System.Data
> Imports System.IO
> Imports System.IO.Directory
> Imports System.Configuration
> Imports System.Reflection
>
> Public Class create_DB
>
> Public SQLEngine As SqlServerCe.SqlCeEngine
> Public dir As String
> Public SQL As String
> Dim connString As String
> Dim msg As String
> Dim connCE As SqlCeConnection
> Dim comnd As SqlCeCommand
>
>
> Public Sub New()
> Try
> dir = "\db.sdf"
>
> Catch ex As Exception
>
> MsgBox(ex.ToString())
> Return
> End Try
>
> Try
> If File.Exists(dir) Then
> File.Delete(dir)
> End If
> Catch ex As Exception
> MsgBox(dir)
> Return
> End Try
> Try
> connString = "data source=" & dir
> SQLEngine = New SqlServerCe.SqlCeEngine(connString)
> SQLEngine.CreateDatabase()
>
> REM Create an SQL command to create A TABLE
>
> SQL = "CREATE TABLE MAIN_INFO ( "
> SQL &= "main_key CHAR(40) PRIMARY KEY, "
> SQL &= "memo_data ntext "
> SQL &= ") ;"
>
>
> Catch ex As Exception
> msg = "create DB"
> MsgBox(ex.ToString(), , msg)
> Return
> End Try
>
> Try
> connCE = New SqlCeConnection(connString)
> connCE.Open()
> Catch ex As Exception
> msg = "Connection:"
> MsgBox(ex.ToString(), , msg)
>
> End Try
>
> comnd = New SqlCeCommand
>
> Try
> comnd.Connection = connCE
> comnd.CommandText = SQL
> MsgBox(SQL)
>
> MsgBox("before execute")
> comnd.ExecuteNonQuery()
> Catch ex As SqlCeException
> MsgBox(ex.Message, , "Message")
> msg = "Execute SQL: "
> MsgBox(ex.ToString(), , msg)
>
> Catch ex As Exception
> msg = "Execute SQL: "
> MsgBox(ex.ToString(), , msg)
> End Try
>
>
> End Sub
>
> End Class
>
> After executing the statement "comnd.ExecuteNonQuery()" I am getting
> "The specified data type is not valid.[Data type,,,,,]
>
> System.Data.SQLServerCE.SQLCeExeption".
>
> Any idea which data type in not valid?
>
> Thanks,
>
> Zalek



Re: Newbie - SQLCE exception. by zalek

zalek
Sat Oct 15 14:46:41 CDT 2005


Yosh wrote:
> Check out the valid datatypes for SQLCE
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqlce/htm/_lce_data_types.asp
>

Thanks Yosh,

The problem was my SQL statement:
SQL &= "main_key CHAR(40) PRIMARY KEY, "

The is no datatype CHAR. After correcting it to NCHAR program worked.

Zalek

>
> "Zalek Bloom" <ZalekBloom@hotmail.com> wrote in message
> news:k79ek1hr3sok9mhs52vnmmk0p3l340r637@4ax.com...
> >I wrote a test program to create a database.
> > Here is the program:
> > Imports System
> > Imports System.Data.SqlServerCe
> > Imports System.Data.Common
> > Imports System.Data
> > Imports System.IO
> > Imports System.IO.Directory
> > Imports System.Configuration
> > Imports System.Reflection
> >
> > Public Class create_DB
> >
> > Public SQLEngine As SqlServerCe.SqlCeEngine
> > Public dir As String
> > Public SQL As String
> > Dim connString As String
> > Dim msg As String
> > Dim connCE As SqlCeConnection
> > Dim comnd As SqlCeCommand
> >
> >
> > Public Sub New()
> > Try
> > dir = "\db.sdf"
> >
> > Catch ex As Exception
> >
> > MsgBox(ex.ToString())
> > Return
> > End Try
> >
> > Try
> > If File.Exists(dir) Then
> > File.Delete(dir)
> > End If
> > Catch ex As Exception
> > MsgBox(dir)
> > Return
> > End Try
> > Try
> > connString = "data source=" & dir
> > SQLEngine = New SqlServerCe.SqlCeEngine(connString)
> > SQLEngine.CreateDatabase()
> >
> > REM Create an SQL command to create A TABLE
> >
> > SQL = "CREATE TABLE MAIN_INFO ( "
> > SQL &= "main_key CHAR(40) PRIMARY KEY, "
> > SQL &= "memo_data ntext "
> > SQL &= ") ;"
> >
> >
> > Catch ex As Exception
> > msg = "create DB"
> > MsgBox(ex.ToString(), , msg)
> > Return
> > End Try
> >
> > Try
> > connCE = New SqlCeConnection(connString)
> > connCE.Open()
> > Catch ex As Exception
> > msg = "Connection:"
> > MsgBox(ex.ToString(), , msg)
> >
> > End Try
> >
> > comnd = New SqlCeCommand
> >
> > Try
> > comnd.Connection = connCE
> > comnd.CommandText = SQL
> > MsgBox(SQL)
> >
> > MsgBox("before execute")
> > comnd.ExecuteNonQuery()
> > Catch ex As SqlCeException
> > MsgBox(ex.Message, , "Message")
> > msg = "Execute SQL: "
> > MsgBox(ex.ToString(), , msg)
> >
> > Catch ex As Exception
> > msg = "Execute SQL: "
> > MsgBox(ex.ToString(), , msg)
> > End Try
> >
> >
> > End Sub
> >
> > End Class
> >
> > After executing the statement "comnd.ExecuteNonQuery()" I am getting
> > "The specified data type is not valid.[Data type,,,,,]
> >
> > System.Data.SQLServerCE.SQLCeExeption".
> >
> > Any idea which data type in not valid?
> >
> > Thanks,
> >
> > Zalek