插入 FoxPro

发布于 2024-09-19 20:16:43 字数 3992 浏览 8 评论 0原文

我已插入到 fOXPRO 中的表 AG_MAS:

private void button1_Click(object sender, EventArgs e)
    {
        OleDbConnection connect = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=pl_prov.dbf");
        try
        {
            connect.Open();
            string strSQL = "insert into ag_mas";
            strSQL += "(ag_code,ag_level,ag_group,ag_rcode,ag_status,";
            strSQL += "ag_type,ag_gender,ag_lname,ag_fname,ag_add1,";
            strSQL += "ag_add2,ag_add3,ag_add4,ag_class,ag_vouch,";
            strSQL += "pl_prov,pl_zone,ag_jdate,ag_ddate,ag_dbrith,ag_bank  ,";
            strSQL += "ag_bankno,ag_telno,ag_faxno,ag_email,ag_ppay,";
            strSQL += "ag_contno,ag_dcont,ag_ladate,ag_lpolno,ag_lendno,";
            strSQL += "ag_comm,ag_maxcom,ag_orcomm,ag_om1com,ag_om2com,";
            strSQL += "ag_om3com,ag_oy1com, ag_oy2com,ag_oy3com,ag_network)";
            strSQL += "values (";
            strSQL += "'" + textBox1.Text + "',";//ag_code
            strSQL += "'" + textBox2.Text + "',";//ag_level
            strSQL += "'" + textBox3.Text + "',";//ag_group
            strSQL += "' ' ,";                                //ag_rcode
            strSQL += "'" + textBox4.Text + "',";//ag_status
            strSQL += "'" + textBox22.Text + "',";//ag_type
            strSQL += "'" + textBox5.Text + "',";//ag_gender
            strSQL += "'" + textBox6.Text + "',";//ag_lname
            strSQL += "'" + textBox7.Text + "',";//ag_fname
            strSQL += "'" + textBox8.Text + "',";//ag_add1
            strSQL += "'" + textBox9.Text + "',";//ag_add2
            strSQL += "'" + comboBox1.Text + "',";//ag_add3
            strSQL += "' ' ,";                                   //ag_add4
            strSQL += "'" + textBox10.Text + "',";//ag_class
            strSQL += "'" + textBox11.Text + "',";//ag_vouch
            strSQL += "'" + comboBox1.SelectedValue + "',";//pl_prov
            strSQL += "' ' ,";                                   //pl_zone
            strSQL += "'" + textBox12.Text + "',";  //ag_jdate
            strSQL += "'1987/10/10',";                             //ag_ddate
            strSQL += "'1987/10/10',";                             //ag_dbirth
            strSQL += "' ' ,";                                   //ag_bank
            strSQL += "' ' ,";                                   //ag_bankno
            strSQL += "' ' ,";                                   //ag_telno
            strSQL += "' ' ,";                                   //ag_faxno
            strSQL += "' ' ,";                                   //ag_email
            strSQL += "'" + textBox13.Text + "',"; //ag_ppay
            strSQL += "'" + textBox15.Text + "',";//ag_contno
            strSQL += "'" + textBox14.Text + "',";//ag_dcont
            strSQL += "'1987/10/10', ";               //ag_ladate
            strSQL += "' ' ,";                                  //ag_lpopno
            strSQL += "' ' ,";                                  //ag_lendno
            strSQL += "0,";                                  //ag_comm
            strSQL += "0,";                                  //ag_maxcom
            strSQL += "0,";                                  //ag_orcomm
            strSQL += "0,";                                  //ag_om1com
            strSQL += "0,";                                  //ag_om2com
            strSQL += "0,";                                  //ag_om3comm
            strSQL += "0,";                                  //ag_oy1com
            strSQL += "0,";                                  //ag_oy2Xcom
            strSQL += "0,";                                  //ag_oy3com
            strSQL += "' ')";                                  //ag_network
            OleDbCommand cmd = new OleDbCommand(strSQL, connect);
            cmd.ExecuteNonQuery();
        }
        catch(Exception err)
        {
            MessageBox.Show(err.Message);
        }
    }
}

但我无法插入。因为错误“数据未匹配”请帮助我。

I HAVE iNSERT TO TABLE AG_MAS IN fOXPRO FOLLOW:

private void button1_Click(object sender, EventArgs e)
    {
        OleDbConnection connect = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=pl_prov.dbf");
        try
        {
            connect.Open();
            string strSQL = "insert into ag_mas";
            strSQL += "(ag_code,ag_level,ag_group,ag_rcode,ag_status,";
            strSQL += "ag_type,ag_gender,ag_lname,ag_fname,ag_add1,";
            strSQL += "ag_add2,ag_add3,ag_add4,ag_class,ag_vouch,";
            strSQL += "pl_prov,pl_zone,ag_jdate,ag_ddate,ag_dbrith,ag_bank  ,";
            strSQL += "ag_bankno,ag_telno,ag_faxno,ag_email,ag_ppay,";
            strSQL += "ag_contno,ag_dcont,ag_ladate,ag_lpolno,ag_lendno,";
            strSQL += "ag_comm,ag_maxcom,ag_orcomm,ag_om1com,ag_om2com,";
            strSQL += "ag_om3com,ag_oy1com, ag_oy2com,ag_oy3com,ag_network)";
            strSQL += "values (";
            strSQL += "'" + textBox1.Text + "',";//ag_code
            strSQL += "'" + textBox2.Text + "',";//ag_level
            strSQL += "'" + textBox3.Text + "',";//ag_group
            strSQL += "' ' ,";                                //ag_rcode
            strSQL += "'" + textBox4.Text + "',";//ag_status
            strSQL += "'" + textBox22.Text + "',";//ag_type
            strSQL += "'" + textBox5.Text + "',";//ag_gender
            strSQL += "'" + textBox6.Text + "',";//ag_lname
            strSQL += "'" + textBox7.Text + "',";//ag_fname
            strSQL += "'" + textBox8.Text + "',";//ag_add1
            strSQL += "'" + textBox9.Text + "',";//ag_add2
            strSQL += "'" + comboBox1.Text + "',";//ag_add3
            strSQL += "' ' ,";                                   //ag_add4
            strSQL += "'" + textBox10.Text + "',";//ag_class
            strSQL += "'" + textBox11.Text + "',";//ag_vouch
            strSQL += "'" + comboBox1.SelectedValue + "',";//pl_prov
            strSQL += "' ' ,";                                   //pl_zone
            strSQL += "'" + textBox12.Text + "',";  //ag_jdate
            strSQL += "'1987/10/10',";                             //ag_ddate
            strSQL += "'1987/10/10',";                             //ag_dbirth
            strSQL += "' ' ,";                                   //ag_bank
            strSQL += "' ' ,";                                   //ag_bankno
            strSQL += "' ' ,";                                   //ag_telno
            strSQL += "' ' ,";                                   //ag_faxno
            strSQL += "' ' ,";                                   //ag_email
            strSQL += "'" + textBox13.Text + "',"; //ag_ppay
            strSQL += "'" + textBox15.Text + "',";//ag_contno
            strSQL += "'" + textBox14.Text + "',";//ag_dcont
            strSQL += "'1987/10/10', ";               //ag_ladate
            strSQL += "' ' ,";                                  //ag_lpopno
            strSQL += "' ' ,";                                  //ag_lendno
            strSQL += "0,";                                  //ag_comm
            strSQL += "0,";                                  //ag_maxcom
            strSQL += "0,";                                  //ag_orcomm
            strSQL += "0,";                                  //ag_om1com
            strSQL += "0,";                                  //ag_om2com
            strSQL += "0,";                                  //ag_om3comm
            strSQL += "0,";                                  //ag_oy1com
            strSQL += "0,";                                  //ag_oy2Xcom
            strSQL += "0,";                                  //ag_oy3com
            strSQL += "' ')";                                  //ag_network
            OleDbCommand cmd = new OleDbCommand(strSQL, connect);
            cmd.ExecuteNonQuery();
        }
        catch(Exception err)
        {
            MessageBox.Show(err.Message);
        }
    }
}

BUT I CAN'T INSERT. BECAUSE ERROR "DATA MISS MATCH" PLEASE HELP ME.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暖心男生 2024-09-26 20:16:44

当您尝试将不适当的数据类型插入字段时,会发生数据类型不匹配错误。例如,如果您尝试将字符串存储到整数字段中。

乍一看,我认为你的日期格式有问题。将“'1987/10/10',”更改为“{^1987-10-10},”。

如果更改日期不能解决问题,如果您可以向我显示 strSQL 变量的结果和 ag_mas 表的结构,将会很有帮助。

A Data Type Mismatch error occurs when you try to insert an inappropriate data type into a field. For example, if you try to store a string into an integer field.

At first glance I think the format of your dates is the problem. Change "'1987/10/10'," to "{^1987-10-10},".

If changing the dates does not correct the problem, it would be helpful if you could show me the result of the strSQL variable and structure of the ag_mas table.

抠脚大汉 2024-09-26 20:16:44

我同意 Frank 关于解决方案的观点,并且我相信 DRapp 关于您如何处理插入语句的观点是正确的。为了添加 DRapp 的建议,我想指出您可以使用 LINQ to VFP 来处理写入你所有的sql命令。

I agree with Frank in regards to a solution and I believe that DRapp has a valid point about how you are going about your insert statement. To add to DRapp’s suggestion, I’d like to point out that you could use LINQ to VFP to handle writing all your sql commands.

梦里寻她 2024-09-26 20:16:43

我同意弗兰克关于日期问题的观点......它也可能尝试将文本放入数字字段(或任何其他此类交换)。

然而,一个更大的问题可能是,如果/当你开始使用真正的 SQL 数据库,如 Oracle、SQL-Server、MySQL 等......(并不是说我有任何反对 VFP 的想法,并且自 85 年以来一直在使用 Foxpro 进行编程)但是,像您这样执行 SQL 语句(尤其是在任何基于 Web 的系统中)会让您很容易受到 SQL 注入攻击。

最好使用参数化查询/插入/更新/删除。

I agree with Frank on the issue with dates... It could also be trying to do a text into a numeric field (or any other such swapping).

However, a bigger issue might be if/when you get into using a true SQL database such as Oracle, SQL-Server, MySQL, etc... (not that I have anything against VFP and have been programming with Foxpro since '85) But doing SQL statements like you have, especially in any web-based system would leave you wide-open to SQL-injection attacks.

Its better to use parameterized query/insert/update/deletes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文