我下面的代码显示错误“输入字符串的格式不正确”
Microsoft.Practices.EnterpriseLibrary.Data.Database Obj = Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase("InvoiceConString");
//Create your DbCommand
DbCommand com =Obj.GetStoredProcCommand("StoredProcedure2", InvoiceComments, Convert.ToDateTime(InvoiceDate), ProductName, Description, Convert.ToInt32(Qty), Convert.ToInt32(Amount), Convert.ToInt32(TaxAmount), Convert.ToInt32(paidAmount), CustomerName, CustomerAddress, Convert.ToInt32(UnitCost), Convert.ToInt32(InvoiceReference));
//Execute
int rows =com.ExecuteNonQuery();
con.Close();
return "data Updated Successfully";
我的连接字符串如下
static string conStr = ConfigurationManager.ConnectionStrings["InvoiceConString"].ConnectionString;
但是当我不使用 Microsoft.Practices.EnterpriseLibrary.Data.Database 并更新记录时,它不会显示任何错误并且记录可以轻松获取更新。
注意:-我在转换任何变量时都没有犯任何错误,因为通过相同的变量我正在更新记录如果我像下面这样更新它们
SqlCommand com = new SqlCommand("StoredProcedure2", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@InvoiceComments", SqlDbType.VarChar, 150).Value = InvoiceComments;
com.Parameters.Add("@InvoiceDate", SqlDbType.DateTime).Value = Convert.ToDateTime(InvoiceDate);
com.Parameters.Add("@ProductName", SqlDbType.VarChar, 50).Value = ProductName;
com.Parameters.Add("@Description", SqlDbType.VarChar, 150).Value = Description;
com.Parameters.Add("@Qty", SqlDbType.Int).Value = Convert.ToInt32(Qty);
com.Parameters.Add("@Amount", SqlDbType.Int).Value = Convert.ToInt32(Amount);
com.Parameters.Add("@TaxAmount", SqlDbType.Int).Value = Convert.ToInt32(TaxAmount);
com.Parameters.Add("@PaidAmount", SqlDbType.Int).Value = Convert.ToInt32(paidAmount);
com.Parameters.Add("@CustomerName", SqlDbType.VarChar, 50).Value = CustomerName;
com.Parameters.Add("@CustomerAddress", SqlDbType.VarChar, 150).Value = CustomerAddress;
com.Parameters.Add("@UnitCost", SqlDbType.Int).Value = Convert.ToInt32(UnitCost);
com.Parameters.Add("@InvoiceReference", SqlDbType.Int).Value = Convert.ToInt32(InvoiceReference);
con.Open();
com.ExecuteNonQuery();
con.Close();
上面的代码工作正常,这段代码没有问题。