插入FOXPRO

时间:2010-09-16 10:15:21

标签: visual-foxpro

我已经开始在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);
        }
    }
}

但我不能插入。因为错误的“数据小姐比赛”请帮助我。

3 个答案:

答案 0 :(得分:1)

我同意Frank关于日期的问题......它也可能试图将文本写入数字字段(或任何其他此类交换)。

然而,更大的问题可能是,如果/当你开始使用真正的SQL数据库,如Oracle,SQL-Server,MySQL等...(不是我有任何针对VFP的东西,并且自从用Foxpro编程以来) '85)但是像你一样做SQL语句,尤其是在任何基于Web的系统中,都会让你对SQL注入攻击开放。

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

答案 1 :(得分:0)

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

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

如果更改日期不能解决问题,那么如果你能告诉我strSQL变量的结果和ag_mas表的结构会很有帮助。

答案 2 :(得分:0)

我同意Frank的解决方案,我相信DRapp对你如何处理你的插入声明有一个有效的观点。要添加到DRapp的建议,我想指出您可以使用LINQ to VFP来处理所有sql命令的编写。