0
我会做很多这样的事情,有人可以帮我把它转换成类吗?创建一个类来检查sqlserver中的值是否为空
private void CheckingForCostID()
{
//if CostID is exist then error.
newConnection.ConnectionM();
SqlCommand cmd = SqlConnectionOLTP.cn.CreateCommand();
cmd.CommandText = "SELECT CostCategoryID FROM CostCategory WHERE CostCategoryName [email protected] AND Description [email protected]";
cmd.Parameters.AddWithValue("@costcategoryname", format.SetText(textBoxCostName));
cmd.Parameters.AddWithValue("@description", format.SetText(textBoxCostDescription));
var costid = cmd.ExecuteScalar();
if (costid == null)
{
CreateCostCategoryData();
}
else
MessageBox.Show("Cost Category already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
SqlConnectionOLTP.cn.Close();
}
Newing了库?有人没有听说过单元测试,依赖注入,事务,工作单元,回滚。这是不好的建议。它应该是一个注入的'IRepository',至少。 – user9993
他必须更改这段代码,他不重构所有项目结构我的解决方案不是最好的方法,但解决他的问题。 –