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