Please help me to solve this code if there is error..I have this error message-
Conversion failed when converting the varchar value '@IDPRO ' to data type int.
.
I work with SQL 2014 and VS 2012
CLASSES
class DataAccessLayer
{
SqlConnection SQLcn;
public DataAccessLyer()
{
SQLcn = new SqlConnection(@"server=.\SQLEXPRESS;database=Product_DB;integrated security=true");
}
public void open()
{
if (SQLcn.State != ConnectionState.Open)
{
SQLcn.Open();
}
}
public void close()
{
if (SQLcn.State == ConnectionState.Open)
{
SQLcn.Close();
}
}
public DataTable selectdata(string storage_proc, SqlParameter[] param)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = storage_proc;
cmd.Connection = SQLcn;
if (param != null)
{
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public void Executecommand(string storage_proc, SqlParameter[] param)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = storage_proc;
cmd.Connection = SQLcn;
if (param != null)
{
cmd.Parameters.AddRange(param);
}
cmd.ExecuteNonQuery();
}
class CLS_PRODUCT
{
public DataTable GETCATOGRY()
{
DAL.DataAccessLyer DAL = new DAL.DataAccessLyer();
DAL.open();
DataTable dt = new DataTable();
dt = DAL.selectdata("GETCATOGRY", null);
DAL.close();
return dt;
}
public void ADD_PRODUCT(string ID_PRODUCT, string LABEL, int QTE, string PRICE, byte[]IMAGE, int ID_CAT)
{
DAL.DataAccessLyer DAL = new DAL.DataAccessLyer();
DAL.open();
SqlParameter [] param=new SqlParameter[6];
param[0] = new SqlParameter("@IDPRO", SqlDbType.VarChar, 50);
param[0].Value = ID_PRODUCT;
param[1] = new SqlParameter("@LABELPRO", SqlDbType.VarChar, 50);
param[1].Value = LABEL;
param[2] = new SqlParameter("@QTEPRO", SqlDbType.Int);
param[2].Value = QTE;
param[3] = new SqlParameter("@PRICEPRO", SqlDbType.VarChar, 50);
param[3].Value = PRICE;
param[4] = new SqlParameter("@IMAGEPRO", SqlDbType.Image);
param[4].Value = IMAGE;
param[5] = new SqlParameter("@IDCAT", SqlDbType.Int);
param[5].Value = ID_CAT;
DAL.Executecommand("ADD_PRODUCT",param);
DAL.close();
}
Stored Procedure
ALTER PROC [dbo].[ADD_PRODUCT]
@IDPRO varchar(50) ,
@LABELPRO varchar(50),
@QTEPRO int,
@PRICEPRO varchar(50),
@IMAGEPRO image,
@IDCAT int
<small><big></big></small>
AS
INSERT INTO PRODUCTS
(ID_PRODUCT
,LABEL_PRODUCT
,QTE_PRODUCT
,PRICE_PRODUCT
,IMAGE_PRODUCT
,ID_CAT)
VALUES
(@IDPRO
, @LABELPRO
, @QTEPRO
, @PRICEPRO
, @IMAGEPRO
, @IDCAT)
ALTER PROC [dbo].[GETCATOGRY]
AS
SELECT * FROM CATEGORY
Forms Code
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace PRODUCTS_MANAGMENT.PL
{
public partial class Frm_Add_prodc : Form
{
public string STATE = "ADD";
BL.CLS_PRODUCT PRC = new BL.CLS_PRODUCT();
public Frm_Add_prodc()
{
InitializeComponent();
cmbCAT.DataSource = PRC.GETCATOGRY();
cmbCAT.DisplayMember = "DESCREPTION_CAT";
cmbCAT.ValueMember = "ID_CAT";
}
private void btnADD_Click(object sender, EventArgs e)
{
MemoryStream ms = new MemoryStream();
picprodc.Image.Save(ms, picprodc.Image.RawFormat);
byte[] IMAGE = ms.ToArray();
PRC.ADD_PRODUCT(TXTREF.Text, TXTDES.Text, Convert.ToInt32(txtqnt.Text), txtprice.Text, IMAGE, Convert.ToInt32(cmbCAT.SelectedValue));
MessageBox.Show("SUCCESS ADDING", "ADD OPERATION ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}