有没有办法测试哪些组合返回结果?

时间:2014-06-20 04:44:00

标签: c# mysql

好的,澄清一下,我有一个方法,从一系列4个组合框中获取数据库中的字符串,具体取决于表单的输入形式。

事实上,在Db中,一些条目缺少字段,这意味着某些查询不会返回任何内容。

有没有办法自动测试哪些字段不会返回值,或者更改查询会更好?

这是我目前的代码:

形式:

private void cmbCoreCfg_SelectedIndexChanged(object sender, EventArgs e)
{
    if (cmbCoreCfg.Text != "" && cmbMetal.Text != "")
    {
            CableID_Controller.GetSupplierId(this);
    }
}

控制器:

public static void GetSupplierId(CableID_CreateView CView)
{
    SupplierID_Controller.SModel = new SupplierID_Model();

    SupplierID_Controller.SModel.SupplierID = 3;
    SupplierID_Controller.SModel.CoreConfig = CView.cmbCoreCfg.Text;
    SupplierID_Controller.SModel.Insulation = CView.cmbInsulation.Text;
    SupplierID_Controller.SModel.Xsec = CView.cmbXsec.Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];
    SupplierID_Controller.SModel.CondConfig = condCfg = CView.cmbXsec.Text.Split('-')[1].Trim();
    SupplierID_Controller.SModel.Metal = CView.cmbMetal.Text;

    Database_Facade.Operation_Switch(SupplierID_Controller.OPREAD);

    CView.txtProductCode.Text = SupplierID_Controller.SModel.PrdtCd;
}

数据库查询:

{
    mySqlCommand = mySqlConnect.CreateCommand();
    mySqlCommand.CommandText = "SELECT PrdtCd FROM SupplierInfo WHERE Xsec = @Xsec AND CoreConfg = @CoreConfg AND CondConfg = CondConfg "
        + "AND Insul = @Insul AND Metal = @Metal;";

    mySqlCommand.Parameters.Add("@Xsec", MySqlDbType.VarChar);
    mySqlCommand.Parameters.Add("@CoreConfg", MySqlDbType.VarChar);
    mySqlCommand.Parameters.Add("@CondConfg", MySqlDbType.VarChar);
    mySqlCommand.Parameters.Add("@Insul", MySqlDbType.VarChar);
    mySqlCommand.Parameters.Add("@Metal", MySqlDbType.VarChar);

    mySqlCommand.Parameters["@Xsec"].Value = SModel.Xsec;
    mySqlCommand.Parameters["@CoreConfg"].Value = SModel.CoreConfig;
    mySqlCommand.Parameters["@CondConfg"].Value = SModel.CondConfig;
    mySqlCommand.Parameters["@Insul"].Value = SModel.Insulation;
    mySqlCommand.Parameters["@Metal"].Value = SModel.Metal;

    mySqlReader = mySqlCommand.ExecuteReader();

    while (mySqlReader.Read())
    {
        SModel.PrdtCd = Convert.ToString(mySqlReader["PrdtCd"]);
    }
    mySqlReader.Close();
    mySqlCommand.ExecuteNonQuery();
}

0 个答案:

没有答案