无法将值导入SQL Server数据库

发布于 2025-02-11 09:43:18 字数 1650 浏览 0 评论 0原文

我一直在尝试将一个条目添加到现有表中。每当我尝试添加值时(我使用4个名称,desc作为五号持有人值来测试将项目添加到表中),它似乎并未正确导入/添加。我已经检查了连接是否正确建立,请检查该方法是否被调用,什么也没有更改。我没有收到输出或错误列表中的错误。我唯一能够发现的唯一重要的事情是,如果我对表数据有现有视图并尝试刷新它,我会得到“无法导入此数据库。它是不支持的SQL Server版本,或者是不支持的数据库兼容性。”错误。如果我关闭视图并通过服务器资源管理器重新打开它,那么刷新的行为正常,但没有发生任何更改。

//由于复制粘贴而奇怪的代码格式化很奇怪

    public static SqlConnection Get_DB_Connection()
    {
         string cn_String = Properties.Settings.Default.birdCategoriesConnectionString;
         SqlConnection cn_connection = new SqlConnection(cn_String);
         if (cn_connection.State != ConnectionState.Open) cn_connection.Open();
         return cn_connection;
    }
    
    public static void AddDataValues()
    {
        try
        {
            SqlConnection connection = Get_DB_Connection(); //Opens new SqlConnection
            string Query = "INSERT dbo.DivisionTable (Id,Name,Description) VALUES (4,'Name','Desc')"; 
            //test Values 4|name|desc
            SqlCommand classCommand = new SqlCommand(Query, connection);
            classCommand.ExecuteNonQuery();
            Debug.WriteLine("Saved");
        }
        catch (SqlException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
             Close_DB_Connection();
        }
    }

    public static void Close_DB_Connection()
    {
        string cn_String = Properties.Settings.Default.birdCategoriesConnectionString;
        SqlConnection cn_connection = new SqlConnection(cn_String);
    
        if (cn_connection.State != ConnectionState.Closed)
            cn_connection.Close();
    }

I've been attempting to add a an entry into an existing table I have. When ever I attempt to add values (I used 4, name, desc as subholder values to test adding items to a table), it does not appear to import/add properly. I've checked if the connection establishes properly, check if the method is being called, and nothing is changed. I receive no errors in output or error list. The only significant thing I've been able to discover is if I have an existing view of the table data and attempt to refresh it, I get a "This database cannot be imported. It is either an unsupported SQL server version or an unsupported database compatibility." error. If I close the view and reopen it through server explorer, refreshing acts normally but no changes have occurred.

//Code Formating is weird due to copy pasting

    public static SqlConnection Get_DB_Connection()
    {
         string cn_String = Properties.Settings.Default.birdCategoriesConnectionString;
         SqlConnection cn_connection = new SqlConnection(cn_String);
         if (cn_connection.State != ConnectionState.Open) cn_connection.Open();
         return cn_connection;
    }
    
    public static void AddDataValues()
    {
        try
        {
            SqlConnection connection = Get_DB_Connection(); //Opens new SqlConnection
            string Query = "INSERT dbo.DivisionTable (Id,Name,Description) VALUES (4,'Name','Desc')"; 
            //test Values 4|name|desc
            SqlCommand classCommand = new SqlCommand(Query, connection);
            classCommand.ExecuteNonQuery();
            Debug.WriteLine("Saved");
        }
        catch (SqlException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
             Close_DB_Connection();
        }
    }

    public static void Close_DB_Connection()
    {
        string cn_String = Properties.Settings.Default.birdCategoriesConnectionString;
        SqlConnection cn_connection = new SqlConnection(cn_String);
    
        if (cn_connection.State != ConnectionState.Closed)
            cn_connection.Close();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文