从数据库中获取布尔值


protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
{
    SqlConnection con = new SqlConnection(@"Data Source=ENTERKEY001;Initial Catalog=ContactManagement;Integrated Security=True");//DataBase Connection
    String NAME = TextBox4.Text;
    SqlCommand getID = new SqlCommand("SELECT ID FROM UserDetailsOne WHERE NAME='" + NAME + "'", con);
    con.Open();
    SqlDataReader dr = getID.ExecuteReader();
    if (dr.Read())
    {
        String ID = dr[0].ToString();
        SqlCommand getBLOCK = new SqlCommand("SELECT BLOCK FROM UserDetailsTwo WHERE ID='" + ID + "'", con);
        dr.Close();
        SqlDataReader dr0 = getBLOCK.ExecuteReader();
        if (dr0.Read())
        {
            String BLOCK = dr0[0].ToString();
            if (BLOCK == "false")
            {
                SqlCommand cmd = new SqlCommand("select NAME,UserDetailsOne.ID,ADDRESS,GENDER,MOBILENO,PHOTO from UserDetailsOne left join UserDetailsTwo on UserDetailsOne.ID=UserDetailsTwo.ID where NAME like @NAME", con);
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                GridView1.DataSource = dt;
                GridView1.DataBind();
                con.Close();
            }
            else
            {
                Response.Redirect("1.aspx");
            }
        }
    }
}
if(Convert.ToBoolean(tablename.Rows[index row][index columns])=true)
{
  //do sth
}

访问表的一种方法是列的索引,或者如果您想找到列名,可以在[]中写入name"

相关内容

  • 没有找到相关文章

最新更新