I'm getting this error and although I know it's been asked many many times, I tried to research my error and still nothing's work.
Is there any error to my code ? I hope someone would be able to help in this matter. I've been stuck on this for a week. I tried differnt opinions of other developer but still nothing solves.
Stored Procedure:
ALTER PROCEDURE dbo.AddProduct
@ID int,
@Image varbinary(max),
@Supplier varchar(50),
@Codeitem varchar(50),
@Itemdescription varchar(50),
@Date varchar(50),
@Quantity varchar(50),
@Unitcost varchar(50),
@ADD nvarchar(50)
AS
BEGIN
IF @ADD = 'Insert'
INSERT INTO dbo.employee_product
(
Image,
Supplier,
Codeitem,
Itemdescription,
Date,
Quantity,
Unitcost
)
VALUES
(
@Image,
@Supplier,
@Codeitem,
@Itemdescription,
@Date,
@Quantity,
@Unitcost
)
END
My Code:
byte[] image = null;
var stream = new FileStream(this.txt_path.Text, FileMode.Open, FileAccess.Read);
var read = new BinaryReader(stream);
image = read.ReadBytes((int)stream.Length);
using (var con = SQLConnection.GetConnection())
{
if (string.IsNullOrEmpty(cbox_supplier.Text) || string.IsNullOrEmpty(txt_code.Text) || string.IsNullOrEmpty(txt_item.Text) || string.IsNullOrEmpty(txt_quantity.Text) || string.IsNullOrEmpty(txt_cost.Text))
{
MetroMessageBox.Show(this, "Please input the Required Fields", "System Message:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
var selectCommand = new SqlCommand("AddProduct", con);
selectCommand.CommandType = CommandType.StoredProcedure;
selectCommand.Parameters.AddWithValue("@ADD", "Insert");
selectCommand.Parameters.AddWithValue("@ID",SqlDbType.Int ).Value = 0;
selectCommand.Parameters.AddWithValue("@Image", image);
selectCommand.Parameters.AddWithValue("@Supplier", cbox_supplier.Text);
selectCommand.Parameters.AddWithValue("@Supplier", cbox_supplier.Text.Trim());
selectCommand.Parameters.AddWithValue("@Codeitem", txt_code.Text.Trim());
selectCommand.Parameters.AddWithValue("@Itemdescription", txt_item.Text.Trim());
selectCommand.Parameters.AddWithValue("@Date", txt_date.Text.Trim());
selectCommand.Parameters.AddWithValue("@Quantity", txt_quantity.Text.Trim());
selectCommand.Parameters.AddWithValue("@Unitcost", txt_cost.Text.Trim());
selectCommand.ExecuteNonQuery();
MessageBox.Show("Added successfully", "SIMS", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
_view._product();
}
}