[英]How can I show the relationship based SQL Server table value in label in C#
I have more than two SQL Server tables which have relationships. 我有两个以上具有关系的SQL Server表。 But when I want to show two columns in label it gives me an error. 但是,当我想在标签中显示两列时,会给我一个错误。 I want to show Aurthorname
and Catagoryname
where book id is equal to textbox.text
: 我想告诉Aurthorname
和Catagoryname
其中书籍ID等于textbox.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();
}
You don't need to prefix the column name with the tablename. 您无需在列名前面加上表名。 Just use 只需使用
label20.Text = koo["Aurthorname"].ToString();
label21.Text = koo["CatagoryName"].ToString();
By the way, you have switched the tablename with the column name for the "Category" field 顺便说一句,您已将表名与“类别”字段的列名切换了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.