每次为真时,C#bool行都会计入空列 [英] C# bool rows count with empty columns every time true

查看:63
本文介绍了每次为真时,C#bool行都会计入空列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i have 2 columns book1 and book2 to in borrowes table but some time users borrowed the book and some time no, so i need to delete user which not borrowed any book (book1 or book2). but i got every time value in True... let me know what can i do thanks. i tried this...





我尝试了什么:





What I have tried:

con.Open();

        bool readerHasRows = false;
        string brid = txtBr_id.Text;
        String syntax = "SELECT book1, book2 FROM Borrowes WHERE brId = @brid";
        using (SqlCommand cmd = new SqlCommand(syntax, con))
        {
            cmd.Parameters.AddWithValue("@brid", txtBr_id.Text);


            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                readerHasRows = (!reader[0].IsDBNull);
            }
        }
        con.Close();

     if (readerHasRows == true)
        {
            MessageBox.Show("This borrower has borrowed the book please collect the book first.");
        }

推荐答案

使用SqlDataReader.HasRows属性(System.Data.SqlClient) [ ^ ]。


这篇关于每次为真时,C#bool行都会计入空列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆