下面是一段代码,运行的时候提示“从索引 0 处开始,初始化字符串的格式不符合规范。”
调试时候appPath="\\Program Files\\myDB\\ioriDB6.sdf"
- C# code
public partial class Form1 : Form { string appPath; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { appPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), "ioriDB6.sdf"); createDataBase(); } private void createDataBase() { if (System.IO.File.Exists(appPath)) { //存在 } else { System.Data.SqlServerCe.SqlCeEngine eng = new System.Data.SqlServerCe.SqlCeEngine("Data Source=" + appPath); eng.CreateDatabase(); //连接ce数据库 System.Data.SqlServerCe.SqlCeConnection localcnn = new System.Data.SqlServerCe.SqlCeConnection(appPath); //就是这句出现的“从索引 0 处开始,初始化字符串的格式不符合规范。” localcnn.Open(); StringBuilder sql = new StringBuilder(); sql.Append( "CREATE TABLE user(id varchar(6) primary key not null,name varchar(8),sec char(2))"); System.Data.SqlServerCe.SqlCeCommand cmdSQL = new System.Data.SqlServerCe.SqlCeCommand(sql.ToString(), localcnn); cmdSQL.CommandType = System.Data.CommandType.Text; cmdSQL.ExecuteNonQuery(); } } }
应该怎么改?
------解决方案--------------------
up
------解决方案--------------------
create table 那句 最后加个分号看看