protected void DeleteEvent(object sender, EventArgs e) { UserScreen obj = new UserScreen(); try { obj.delete(string.Format("Delete From dbo.BookTable Where Name='{0}'", GridView1.SelectedRow.Cells[2].Text)); } catch (Exception ex) { throw new Exception(ex.Message); } bind(); }
protected void Button1_Click(object sender, EventArgs e) { var connection = "Data Source=AURBLRLT-439;Initial Catalog=library;Integrated Security=True"; var cnt = Count(); if (check() == 0) { try { string cmd = "Insert Into dbo.BookTable values(@Id,@Name,@Author,@Checked,@BookCount)"; SqlConnection conn = new SqlConnection(connection); SqlCommand command = new SqlCommand(cmd, conn); command.Parameters.AddWithValue("@Name", TextBox3.Text); command.Parameters.AddWithValue("@Author", TextBox1.Text); command.Parameters.AddWithValue("@Id", cnt + 1); command.Parameters.AddWithValue("@Checked", 0); command.Parameters.AddWithValue("@BookCount", Convert.ToInt32(TextBox4.Text)); conn.Open(); command.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { Response.Write(ex.Message); } bind(); TextBox1.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; } else { var count = check(); UserScreen obj = new UserScreen(); var c = Convert.ToInt32(TextBox4.Text) + count; obj.Increment(string.Format("Update dbo.BookTable Set BookCount={0} Where Name='{1}'", c, TextBox3.Text)); bind(); } }