2013-10-12 58 views
0

在SQL Server Compact Edition中,如何以編程方式創建數據庫時定義整數?我試過int,Int32,Bigint,他們都沒有工作,他們都拋出一個異常說數據類型無效?SQL Server Compact在未知數據類型上拋出異常?

string createTable6 = "CREATE TABLE Gates (Gate1In Bigint(5), Gate1Out Bigint(5), Gate2In Bigint(5), Gate2Out Bigint(5), Gate3In Bigint(5), Gate3Out Bigint(5), Gate4In Bigint(5), Gate4Out Bigint(5), Gate5In Bigint(5), Gate5Out Bigint(5))"; 

SqlCeConnection connexion6 = new SqlCeConnection(connectionString); 
SqlCeCommand table6 = new SqlCeCommand(createTable6, connexion6); 

try 
{ 
    connexion6.Open(); 
    table6.ExecuteNonQuery(); 
} 
catch (Exception ex) 
{ 
    MessageBox.Show(ex.ToString()); 
} 

connexion6.Close(); 

回答

1

只需使用bigint沒有括號

string createTable6 = "CREATE TABLE Gates (Gate1In bigint, Gate1Out bigint, " + 
     "Gate2In bigint, Gate2Out bigint, Gate3In bigint, Gate3Out bigint, " + 
     "Gate4In bigint, Gate4Out bigint, Gate5In bigint, Gate5Out bigint)"; 

但是它應該int也行。如果你並不需要所有的整數空間(8個字節),你可以使用整數

1

這是你的數據類型聲明後有括號中的事實:

試試這個:

string createTable6 = "CREATE TABLE Gates (Gate1In Bigint, Gate1Out Bigint, Gate2In Bigint, " + 
     "Gate2Out Bigint, Gate3In Bigint, Gate3Out Bigint, Gate4In Bigint, Gate4Out Bigint, " + 
     "Gate5In Bigint, Gate5Out Bigint)"; 
相關問題