private void refshBtn_Click(object sender, EventArgs e) { borrowDetail.Rows.Clear(); string[,] book = new String[DBCommand.countRowbrw(), 10]; try { book = DBCommand.searchBrw("", "", "", ""); for (int i = 0; i < book.GetLength(0); i++) { borrowDetail.Rows.Add(); for (int j = 0; j < 6; j++) { borrowDetail.Rows[i].Cells[j].Value = book[i, j]; } } } catch (FileLoadException e2) { Console.WriteLine(e2); borrowDetail.Rows.Add(); for (int j = 0; j < 10; j++) { borrowDetail.Rows[0].Cells[j].Value = "N/A"; } } }
public static string[,] searchBrw(string bookName, string ISBN, string writer, string borrower) { SQLiteConnection conn = new SQLiteConnection("data source=libDB.sqlite;"); SQLiteCommand cmd; string sql; int row = 0, i = 0; try { conn.Open(); row = DBCommand.countRowbrw(); string[,] brwdata = new string[row, 6]; sql = "SELECT * FROM borrowData"; cmd = new SQLiteCommand(sql, conn); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { sql = $"SELECT * FROM bookData WHERE ROWID = \"{reader["bookID"]}\""; cmd = new SQLiteCommand(sql, conn); SQLiteDataReader r2 = cmd.ExecuteReader(); brwdata[i, 0] = r2["bookName"].ToString(); brwdata[i, 1] = reader["borrower"].ToString(); brwdata[i, 2] = ""; brwdata[i, 3] = DateTime.Now.ToString(); brwdata[i, 4] = r2["ISBN"].ToString(); brwdata[i, 5] = r2["writer"].ToString(); i++; } return(brwdata); } catch (SQLiteException e) { Console.WriteLine(e); return(new string[1, 10]); } finally { if (conn.State != System.Data.ConnectionState.Closed) { conn.Close(); } } }