I am trying to solve an error I think of converting a variable created by me to store data that is in an Excel sheet.
The error happens when I try to insert the data that is in this variable in the SQL Server
, that is in the (query).
code:
variable declaration:
string valmoradafiscaligualmoradalocal = "";
Information search code:
case 47://coluna 21
if (((WS.Cells[linha, Contcoluna] as Excel.Range).Value) != null)
{
valmoradafiscaligualmoradalocal = Convert.ToString((WS.Cells[linha, Contcoluna] as Excel.Range).Value);
}
continue;
insertion code in sql server:
cmd.CommandText = "INSERT tabela_sacc (Morada_Fiscal_Igual_a_Morada_Local) VALUES ('" + valmoradafiscaligualmoradalocal.ToString() + "')";
connection.Open();
cmd.Connection = connection;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
connection.Close();
valgrupo = null;