求高手解决一下小弟的TreeView控件的问题
public void ShowBook(){
string connStr = "Server=.;Database=Book;UID=sa;pwd=sasa";
string sql = "select * from BookType";
SqlConnection connection = new SqlConnection(connStr);
SqlCommand command = new SqlCommand(sql, connection);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
TreeNode typeNode=new TreeNode(reader["TypeName"].ToString());
int typeId=Convert.ToInt32(reader["TypeId"]);
sql = string.Format("select BookId,BookName from Books where BookType={0}", typeId);
SqlConnection bookConn = new SqlConnection(connStr);
command = new SqlCommand(sql, bookConn);
bookConn.Open();
SqlDataReader bookReader = command.ExecuteReader();
while (bookReader.Read())
{
TreeNode bookNode = new TreeNode(bookReader["BookName"].ToString());
bookNode.Tag = bookReader["BookId"];
typeNode.Nodes.Add(bookNode);
}
bookReader.Close();
bookConn.Close();
this.tvwBook.Nodes[0].Nodes.Add(typeNode);
}
reader.Close();
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
}
提示:指定的参数已超出有效值的范围。参数名:index