我的表中有一个名为AllowComent
. 此列具有位数据类型。
在我的 C# 代码中,我尝试恢复值
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";
}
}
但我得到了错误
Conversion failed when converting the nvarchar value ''1'' to data type int.