【问题标题】:SQL Server Compact throwing exception over unknown data type?SQL Server Compact 在未知数据类型上抛出异常?
【发布时间】:2013-10-20 14:20:03
【问题描述】:

在 SQL Server Compact 版本中,如何在以编程方式创建数据库时定义整数?我试过intInt32Bigint,都不行,都抛出异常说数据类型无效?

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();

【问题讨论】:

    标签: c# sql winforms sql-server-ce


    【解决方案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 个字节),你可以使用 ints

    【讨论】:

      【解决方案2】:

      事实是你在数据类型声明之后有括号:

      试试这个:

      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)";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-24
        • 2016-04-11
        • 2023-04-09
        • 1970-01-01
        • 2018-11-26
        • 1970-01-01
        相关资源
        最近更新 更多