C# 正在尝试从SQL数据库添加数据并打印到双链接列表中
我只是在玩C,我试图将SQL数据库中的数据添加到一个双链接列表中,但我在使用按钮打印时遇到了问题。只是想知道如何正确打印以及如何在按钮中使用它C# 正在尝试从SQL数据库添加数据并打印到双链接列表中,c#,class,linked-list,nodes,doubly-linked-list,C#,Class,Linked List,Nodes,Doubly Linked List,我只是在玩C,我试图将SQL数据库中的数据添加到一个双链接列表中,但我在使用按钮打印时遇到了问题。只是想知道如何正确打印以及如何在按钮中使用它 public class Book { SqlConnection conn; //variables of the Book Table created public int ISBNno; public string Title; public string Ca
public class Book
{
SqlConnection conn;
//variables of the Book Table created
public int ISBNno;
public string Title;
public string Category;
public string Acode;
public Book(int ISBN, string title, string category, string
acode)
//constructor
{
this.ISBNno = ISBN;
this.Title = title;
this.Category = category;
this.Acode = acode;
}
}
public class Structures
{
SqlConnection conn;
public void LoadData()
{
LinkedList<Book> book = new LinkedList<Book>(); // doubly linked list
conn = new SqlConnection(ConfigurationManager.ConnectionStrings[@"dbConnection1"].ConnectionString);
SqlCommand cmd = new SqlCommand("Select * From Book where ISBNno = 123456789", conn); // command to execute
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())// read all records with the ISBNno 123456789
{
Book theBook = new Book(reader.GetInt32(0),
reader.GetString(1), reader.GetString(2), reader.GetString(3));
//new Book node
book.AddFirst(theBook); // add it to the Doubly Linked List
}
foreach (Book t in values)
{
//Formatting code needed for tabbed appearance
Output += "\r\n" + t.Title + "\t" + t.Category;
//etc...
}
return Output += "\r\n";
reader.Close();
conn.Close();
}
public string Output;
public String PrintNode(LinkedList<Book> values) // print nodes
{
foreach (Book t in values)
{
//Formatting code needed for tabbed appearance
Output += "\r\n" + t.Title + "\t" + t.Category;
//etc...
}
return Output += "\r\n";
}
}
我想我的连接工作,但很难说,因为我无法打印。任何帮助都将不胜感激 所以。。。到底发生了什么?你有错误吗?你在使用WinForms、WPF、ASP.Net吗?