0

我有两个以上具有关系的 SQL Server 表。但是当我想在标签中显示两列时,它会给我一个错误。我想显示书籍 ID 等于的Aurthorname位置:Catagorynametextbox.text

SqlConnection con = new SqlConnection("Data Source=SWEETHOME\\SQLEXPRESS;Integrated Security=True");
con.Open();
SqlCommand coo = new SqlCommand("Select Book.BookId , Book.Booktitle, "+ 
                         "Aurthor.Aurthorname, Catagory.Catagoryname, Status.Status, "+
                         "Book.IssuingDate, Book.ReceivingDate, Book.Issuedby " + 
                         "From  Aurthor INNER JOIN Book ON Aurthor.Aurthorid = Book.Aurthorid "+
                         "INNER JOIN Catagory ON Book.Catagoryid = Catagory.Catagoryid INNER " +
                         "JOIN Status ON Book.Statusid = Status.Statusid Where Book.Bookid = '" +
                         textBox2.Text + "'", con);
SqlDataReader koo = coo.ExecuteReader();

while (koo.Read())
{
    label20.Text = koo["Aurthor.Aurthorname"].ToString();
    label21.Text = koo["Catagoryname.Catagory"].ToString();
}

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

5

您不需要在列名前加上表名。只需使用

label20.Text = koo["Aurthorname"].ToString();
label21.Text = koo["CatagoryName"].ToString();

顺便说一句,您已将表名与“类别”字段的列名切换

于 2013-02-24T13:19:33.140 回答