void GetBookByID() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("SELECT * from dbo.book_master_tbl WHERE book_id='" + TextBox_BookId.Text.Trim() + "';", con); SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd); DataTable dataTable = new DataTable(); dataAdapter.Fill(dataTable); if (dataTable.Rows.Count >= 1) { TextBox_BookName.Text = dataTable.Rows[0]["book_name"].ToString(); TextBox_Date.Text = dataTable.Rows[0]["publish_date"].ToString(); TextBox_Edition.Text = dataTable.Rows[0]["edition"].ToString(); TextBox_BookCost.Text = dataTable.Rows[0]["book_cost"].ToString().Trim(); TextBox_Pages.Text = dataTable.Rows[0]["no_of_pages"].ToString().Trim(); TextBox_ActualStock.Text = dataTable.Rows[0]["actual_stock"].ToString().Trim(); TextBox_CurrentStock.Text = dataTable.Rows[0]["current_stock"].ToString().Trim(); TextBox_BookDescription.Text = dataTable.Rows[0]["book_description"].ToString(); /*TextBox_CurrentStock.Text = "" + (Convert.ToInt32(dataTable.Rows[0]["actual_stock"].ToString()) - Convert.ToInt32(dataTable.Rows[0]["current_stock"].ToString()));*/ DropDownList_Language.SelectedValue = dataTable.Rows[0]["language"].ToString().Trim(); DropDownList_Publisher.SelectedValue = dataTable.Rows[0]["publisher_name"].ToString().Trim(); DropDownList_AuthorName.SelectedValue = dataTable.Rows[0]["author_name"].ToString().Trim(); ListBox_Genre.ClearSelection(); string[] genre = dataTable.Rows[0]["genre"].ToString().Trim().Split(','); for (int i = 0; i < genre.Length; i++) { for (int j = 0; j < ListBox_Genre.Items.Count; j++) { if (ListBox_Genre.Items[j].ToString() == genre[i]) { ListBox_Genre.Items[j].Selected = true; } } } global_actual_stock = Convert.ToInt32(dataTable.Rows[0]["actual_stock"].ToString().Trim()); global_current_stock = Convert.ToInt32(dataTable.Rows[0]["current_stock"].ToString().Trim()); global_issued_books = global_actual_stock - global_current_stock; global_filepath = dataTable.Rows[0]["book_img_link"].ToString(); } else { Response.Write("<script>alert('Invalid Book ID');</script>"); } } catch (Exception ex) { } }
protected void Go(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand($"SELECT * FROM book_master_tbl where book_id='{BookID.Text.Trim()}' OR book_name ='{BookName.Text.Trim()}';", Con1.Connect()); SqlDataAdapter addaptor = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); addaptor.Fill(dt); if (dt.Rows.Count >= 1) { cmd = new SqlCommand($"SELECT * FROM book_issue_tbl where book_id='{BookID.Text.Trim()}';", Con1.Connect()); addaptor = new SqlDataAdapter(cmd); DataTable dtt = new DataTable(); addaptor.Fill(dtt); int IssueNumber = dtt.Rows.Count; IssuedBooks.Text = IssueNumber.ToString(); BookName.Text = dt.Rows[0]["book_name"].ToString().Trim(); Date.Text = dt.Rows[0]["publish_data"].ToString().Trim(); Pages.Text = dt.Rows[0]["nr_of_pages"].ToString().Trim(); BookCost.Text = dt.Rows[0]["nr_of_pages"].ToString().Trim(); Stock.Text = dt.Rows[0]["actual_stock"].ToString().Trim(); CurrentStock.Text = dt.Rows[0]["current_stock"].ToString(); Description.Text = dt.Rows[0]["book_description"].ToString().Trim(); ListBox_Genre.ClearSelection(); string[] genre = dt.Rows[0]["genre"].ToString().Split(','); for (int i = 0; i < genre.Length; i++) { for (int j = 0; j < ListBox_Genre.Items.Count; j++) { if (ListBox_Genre.Items[j].ToString() == genre[i]) { ListBox_Genre.Items[j].Selected = true; } } } DropDownList_AuthorName.SelectedValue = dt.Rows[0]["author_name"].ToString().Trim(); DropDownList_Language.SelectedValue = dt.Rows[0]["language"].ToString().Trim(); DropDownList_Publisher.SelectedValue = dt.Rows[0]["publisher_name"].ToString().Trim(); } else { Response.Write("<script>alert(' ID incorect ');</script>"); } }