public int InsertSupplier(Supplier supplier)
{
try
{
comm.CommandText = "INSERT INTO SupplierTable(@sup_id, @Supplier_Name, @Address, @City, @Phone, @Email, @TIN)";
comm.Parameters.AddWithValue("sup_id", supplier.id);
comm.Parameters.AddWithValue("Supplier_Name", supplier.NameSupplier);
comm.Parameters.AddWithValue("Address", supplier.Address);
comm.Parameters.AddWithValue("City", supplier.City);
comm.Parameters.AddWithValue("Phone", supplier.Phone);
comm.Parameters.AddWithValue("Email", supplier.Email);
comm.Parameters.AddWithValue("TIN", supplier.TIN);
comm.CommandType = CommandType.Text;
conn.Open();
return comm.ExecuteNonQuery();
}
catch (Exception)
{
}
finally
{
if (conn != null)
{
conn.Close();
}
}
}
如果发生异常,您的方法返回而不return
。
在末尾添加类似return -1;
的内容:
public int InsertSupplier(Supplier supplier)
{
try
{
// your code here
}
catch (Exception)
{
}
finally
{
if (conn != null)
{
conn.Close();
}
}
return -1; // or change this to more proper value
}