0
這是我的代碼創建一個.ACCDB文件,如果它不能找到一個:錯誤,當我試圖創建在C#中.ACCDB文件
Catalog cat = new CatalogClass();
string createStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/saveDB.accdb;";
cat.Create(createStr);
Table tbl = new Table();
tbl.Name = "saveDB";
tbl.Columns.Append("ID", DataTypeEnum.adGUID);
tbl.Columns.Append("Tensiune", DataTypeEnum.adDouble);
tbl.Columns.Append("Frecventa", DataTypeEnum.adDouble);
tbl.Columns.Append("Rezistenta", DataTypeEnum.adDouble);
tbl.Columns.Append("Inductanta", DataTypeEnum.adDouble);
tbl.Columns.Append("Capacitate", DataTypeEnum.adDouble);
tbl.Columns.Append("Elemente", DataTypeEnum.adVarWChar, 25);
tbl.Columns.Append("Tip", DataTypeEnum.adVarWChar, 25);
cat.Tables.Append(tbl);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(tbl);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat.Tables);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat.ActiveConnection);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cat);
但是,當我在節目中我得到它運行這種運行時錯誤:
System.Runtime.InteropServices.COMException (0x80004005): Not a valid file name.
at ADOX.CatalogClass.Create(String ConnectString)
我想不出有什麼用文件名的問題,因此,如果任何人有任何想法,請幫助。
的路徑是我會使用的格式不。試試它與一個實際的FullPath srting即C:\ SomeDir \ AnotherDir \ File.accdb ... – MoonKnight 2012-04-19 15:43:21
我想了解,但我不能這樣做,因爲我會把這個程序給其他人,我不知道在哪裏他們會安裝它。 – 2012-04-19 15:48:54
我修好了。我會發布解決方案時,我發現當網站允許我(7小時)。 – 2012-04-19 16:13:39