i am importing exel file into database but giving error The parameterized query '(@OrderID int,@CustomerName varchar(20),@Address varchar(50),@Em' expects the parameter '@OrderID', which was not supplied.
DataTable dt = new DataTable();
dt.Columns.Add("OrderID");
dt.Columns.Add("CustomerName");
dt.Columns.Add("Address");
dt.Columns.Add("Email");
dt.Columns.Add("Total");
string path = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Imported file/" + path));
path = Server.MapPath("~/Imported file/" + path);
TextFieldParser txtp = new TextFieldParser(path);
txtp.Delimiters = new string[] { "," };
txtp.TrimWhiteSpace = true;
while (!txtp.EndOfData)
{
string[] fields = txtp.ReadFields();
dt.Rows.Add(fields.Equals("OrderID"));
dt.Rows.Add(fields.Equals("CustomerName"));
dt.Rows.Add(fields.Equals("Address"));
dt.Rows.Add(fields.Equals("Email"));
dt.Rows.Add(fields.Equals("Total"));
}
con = Connectivity.GetConnection();
string import = "Insert into Customer (OrderID,CustomerName,Address,Email,Total) values(@OrderID,@CustomerName,@Address,@Email,@Total)";
SqlCommand cmd = new SqlCommand(import, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
cmd.Parameters.Clear();
cmd.Parameters.Add("@OrderID", SqlDbType.Int);
cmd.Parameters.Add("@CustomerName", SqlDbType.VarChar, 20, "CustomerName");
cmd.Parameters.Add("@Address", SqlDbType.VarChar, 50, "Address");
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 50, "Email");
cmd.Parameters.Add("@Total", SqlDbType.Float);
cmd.ExecuteNonQuery();
int result = da.Update(dt);