Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I'm trying to create a database with a table in it programatically.

C#
SqlCeEngine engine = new SqlCeEngine(connStr);
engine.CreateDatabase();

SqlCeConnection conn = new SqlCeConnection(connStr);
conn.Open();

SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "CREATE TABLE Log(Type string,Rego float)";
cmd.ExecuteNonQuery();        


However when I run it I get this error:

>>The specified data type is not valid. [ Data type (if known) = string ]

If I set them both to float it works fine. It also doesn't work for char or text.

If anyone has any idea on the matter it would be most helpful.
Thanks in advance
Posted

Have a look at supported types - see here[^]. There is no support for string or char.
Try using nchar or ntext.
 
Share this answer
 
v2
CREATE TABLE Log(Type text,Rego float)
 
Share this answer
 
SqlCeEngine engine = new SqlCeEngine(connStr);
engine.CreateDatabase();
 
SqlCeConnection conn = new SqlCeConnection(connStr);
conn.Open();
 
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "CREATE TABLE Log(Type ntext,Rego float)";
cmd.ExecuteNonQuery();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900