c#使用ODBC sql在FileMaker表中插入数据

时间:2018-02-07 06:00:17

标签: c# odbc filemaker

我创建了一个将值插入filemaker数据库的应用程序。

我使用ODBC创建连接,它工作正常,插入也工作正常。

插入记录后,查找字段值不会自动更新。

static void Main(string[] args)
        {

            OdbcConnection conn = null;
            OdbcCommand cmd = null;
            OdbcDataAdapter da = new OdbcDataAdapter();
            string temp = "";

            try
            {
                //DRIVER=FileMaker ODBC;
                conn = new OdbcConnection("DSN=SecureDSN;UID=***;PWD=***");
                conn.Open();

                Console.WriteLine(conn.State);

                if (conn.State == System.Data.ConnectionState.Open)
                {
                    cmd = conn.CreateCommand();

                    Console.WriteLine("Input value text");

                    string code = Console.ReadLine();

                    cmd.CommandText = "INSERT INTO MyTable(Field1) VALUES ('test')";
                    cmd.CommandType = System.Data.CommandType.Text;

                    cmd.ExecuteNonQuery();


                    cmd.Dispose();


                    cmd = conn.CreateCommand();
                    cmd.CommandText = "SELECT * FROM MyTable";
                    cmd.CommandType = System.Data.CommandType.Text;
                    DataTable dt = new DataTable();
                    da.SelectCommand = cmd;
                    da.Fill(dt);

                    if (dt.Rows.Count > 0)
                    {
                        int fCount = dt.Rows.Count;
                        Console.WriteLine(fCount);

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            Console.WriteLine("gBarcode=" + Convert.ToString(dt.Rows[i]["gBarCode"]));
                            Console.WriteLine("Boolean=" + Convert.ToString(dt.Rows[i]["Boolean"]));
                            Console.WriteLine("cBoolean=" + Convert.ToString(dt.Rows[i]["cBoolean"]));
                        }
                    }

                    da.Dispose();
                    cmd.Dispose();
                    conn.Close();
                }



            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();
        }
    }

这很好但我无法获取MyTable中的查找值。

当我在filemaker表单中输入值时,将更新Boolean字段的值。为什么它不是从SQL查询计算的。请让我知道解决方案。

1 个答案:

答案 0 :(得分:0)

如果计算字段中没有任何关系值,则它有效,但是当我们有关系值时,它会返回空。