Hello Everybody,I am come in contact a FormatException error when I try to doing the insertion operation in SQL-Server Database.The error is "
error Index (zero based) must be greater than or equal to zero and less than the size of the argument list
".So I didn't find the solution.Please help me in resolving my this issue.Here's below is the code:
public static bool Insert(Products product)
{
string connString = @"Data Source=ps201\SQLEXPRESS;Initial Catalog=E-commerce;Integrated Security=True;Pooling=False";
SqlConnection con = new SqlConnection(connString);
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = string.Format("insert into Products(Name,Price,ImageUrl,Detail,ProductCode,Item,CategoryID) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",product.Name,product.Price,product.ImageUrl,product.Detail,product.ProductCode,product.Item,product.CategoryId);
int rowAffected = com.ExecuteNonQuery();
con.Close();
if (rowAffected > 0)
return true;
else
return false;
}