首页 > 解决方案 > c# 表未显示在 .db3 文件中

问题描述

我这个月才开始使用 c#,当我尝试创建一个新的数据库文件 (.db3) 时遇到了这个问题,该表已创建但当我用 sqlite studio 打开它时没有显示。当我再次尝试时,系统说该表已经存在,但是当我打开 .db3 文件时,该表不在其中,这是我的代码。

SQLiteConnection.CreateFile("C:\\Users\\user\\Desktop\\newTable.db3");
SQLiteConnection createnew = new SQLiteConnection("Data Source=newTable.db3; Version=3;");
createnew.Open();

string newtbl1 = "CREATE TABLE newtest (ID varchar(32) not null, frameId integer not null, posAttrib varchar(128) not null, attrib varchar(64), name varchar(200))";

                    
SQLiteCommand command = new SQLiteCommand(newtbl1, createnew);
command.ExecuteNonQuery();

我试图在谷歌上进行一些搜索,但我一无所获。我不知道如何解决它并且在 c# 方面的知识非常有限,谁能给我一个提示或任何我可以搜索的关键字?非常感谢!

标签: c#sqlite

解决方案


那么,如果您打开 SQLiteConnection,您是打开刚刚在桌面上创建的那个,还是打开任何工作目录中的那个?

试试这种方式:

string dbfile = @"C:\Users\user\Desktop\newTable.db3";
SQLiteConnection.CreateFile(dbfile);
SQLiteConnection createnew = new SQLiteConnection($"Data Source={dbfile}; Version=3;");
createnew.Open();

string newtbl1 = "CREATE TABLE newtest (ID varchar(32) not null, frameId integer not null, posAttrib varchar(128) not null, attrib varchar(64), name varchar(200))";

SQLiteCommand command = new SQLiteCommand(newtbl1, createnew);
command.ExecuteNonQuery();

推荐阅读