简体   繁体   English

如何在C#中的标签中显示基于关系的SQL Server表值

[英]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 : 我想告诉AurthornameCatagoryname其中书籍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.

相关问题 如何检索SQL Server表的列值并将其存储在label.C#ASP.Net中的文本 - How to retrieve column value of sql server table and store it in label.Text of c# ASP.Net 如何获取列的值并将其放入标签C#和SQL Server - How to get value of columns and put it into label C# & SQL Server 如何在标签C#中显示组合框的选定值? - How do I show the selected value of a combobox in a label c#? 如何在C#的标签中显示货币符号? - How can I show currency symbol in a label in c#? 如何使用SQL Server CE和C#更新dB表中的单元格值(Visual Studio 2010) - How can I update a cell value in a dB table, using SQL Server CE and C# (Visual Studio 2010) 如何检索SQL Server 2005表的列值并将其存储在label.C#ASP.Net中的文本 - How to retrieve column value of sql server 2005 table and store it in label.Text of c# ASP.Net 如何通过单击C#中的图片框来更改标签值? - How can I change label Value by clicking in a picturebox in C#? 如何根据条件在 C# 中的标签中显示值的颜色? - How can I show the color of a value in a <td> tag in C# based on condition? 如何仅使用sql在c#中的表中显示新行或更新行? - How can i only show the new or updated rows in a table in c# using sql? 将值插入 C# 中的 SQL 服务器表后,如何将值加 1? - How do I add 1 to a value after it's inserted into SQL Server table in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM