0% found this document useful (0 votes)
25 views

Ass 12

This document contains code for a book management program. It includes: 1) A Program class that defines the main entry point and runs the application, enabling styles and setting compatibility. 2) A BookClass that defines methods for adding a new book to a SQL database by opening a connection, defining an insert command with parameters, and executing it. 3) A method in BookClass to search the book database by name or value, opening a connection, defining a select command, filling a dataset and setting the results as the data source for a datagridview.

Uploaded by

Milan Thummar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Ass 12

This document contains code for a book management program. It includes: 1) A Program class that defines the main entry point and runs the application, enabling styles and setting compatibility. 2) A BookClass that defines methods for adding a new book to a SQL database by opening a connection, defining an insert command with parameters, and executing it. 3) A method in BookClass to search the book database by name or value, opening a connection, defining a select command, filling a dataset and setting the results as the data source for a datagridview.

Uploaded by

Milan Thummar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program.

cs
using using using using System; System.Collections.Generic; System.Linq; System.Windows.Forms;

namespace Book_Module { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } }

Book.class
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; namespace Book_Module { class BookClass { SqlConnection conn = new SqlConnection(@"Data Source=ALPESHPC\SqlExpress;Initial Catalog=StudentDetail;Integrated Security=True"); public void AddBook(int b_id,string b_title,string b_author,int b_price) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "insert into BookDetail(BookId,BookName,BookAuthor,BookPrice) values(@bookid,@booktitle,@bookauthor,@bookprice)"; cmd.Parameters.Add(new SqlParameter ("@bookid",SqlDbType .Int )); cmd.Parameters["@bookid"].Value = b_id; cmd.Parameters.Add(new SqlParameter("@booktitle", SqlDbType.VarChar )); cmd.Parameters["@booktitle"].Value = b_title;

cmd.Parameters.Add(new SqlParameter("@bookauthor", SqlDbType.VarChar)); cmd.Parameters["@bookauthor"].Value = b_author; cmd.Parameters.Add(new SqlParameter("@bookprice", SqlDbType.Int)); cmd.Parameters["@bookprice"].Value = b_price; cmd.ExecuteNonQuery(); conn.Close(); } public void SearchBook(string searchbyname,string searchbyvalue,DataGridView sdg) { SqlConnection conn = new SqlConnection(@"Data Source=ALPESHPC\SqlExpress;Initial Catalog=StudentDetail;Integrated Security=True"); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "select * from BookDetail where " + searchbyname + " = '" + searchbyvalue + "'"; SqlDataAdapter adapter = new SqlDataAdapter(cmd); conn.Open(); DataSet ds = new DataSet(); adapter.Fill(ds, "BookDetail"); sdg.DataSource = ds.Tables["BookDetail"];

} } }

You might also like