I have a column in my table called AllowComent. This column has bit data type.
In my C# code I try recover the value
protected string RecoverAllowComent(string id)
{
try
{
using(SqlConnection conexao = new SqlConnection(_conexao))
{
SqlCommand comando = new SqlCommand();
comando.CommandText = "SELECT AllowComent FROM San_Blog WHERE Id = @Id";
comando.Parameters.Add(new SqlParameter("@Id", id));
comando.CommandType = CommandType.Text;
comando.Connection = conexao;
conexao.Open();
comando.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(comando);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
return dt.Rows[0].ItemArray[0].ToString();
}
else
return "False";
}
}
catch
{
return "False";
}
}
But I got the error
Conversion failed when converting the nvarchar value ''1'' to data type int.
You are passing passing
idwhich has type string. You need to passinttoparameterid.Change
To
If it is possible you can change type of your parameter ID of RecoverAllowComent to int to get away from type casting string to int.