I have a book entry page design in asp.net 2.0, I can already add a new row to the database table by having to enter
details of the book into textboxes and then clicking a button. My problem is, i want the design to automatically
increase the number of books (NUMBER_OF_BOOKS column) whenever a new book is entered having the same title (TITLE
column) that is already stored in the database. But if the book title being entered doesnt exist yet then 1 will be
entered automatically (means you do not enter any number into a textbox for NUMBER_OF_BOOKS column since i dont have a
textbox for that) into the database column.
here is my code for inserting (adding) new book details.
details of the book into textboxes and then clicking a button. My problem is, i want the design to automatically
increase the number of books (NUMBER_OF_BOOKS column) whenever a new book is entered having the same title (TITLE
column) that is already stored in the database. But if the book title being entered doesnt exist yet then 1 will be
entered automatically (means you do not enter any number into a textbox for NUMBER_OF_BOOKS column since i dont have a
textbox for that) into the database column.
here is my code for inserting (adding) new book details.
VB.NET:
Protected Sub addbutton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles addbutton.Click
Dim DBConn As New Data.SqlClient.SqlConnection("DATA SOURCE =xxxx;Initial Catalog= xxx;Integrated
Security=True")
Dim DBCmd As New Data.SqlClient.SqlCommand
Dim DBAdap As New Data.SqlClient.SqlDataAdapter
Dim DS As New Data.DataSet
DBConn.Open()
Try
DBCmd = New Data.SqlClient.SqlCommand("INSERT INTO BOOK
(TITLE, AUTHOR, PUBLISHER) VALUES (@TITLE,
@AUTHOR, @PUBLISHER)", DBConn)
DBCmd.Parameters.Add("@TITLE", Data.SqlDbType.VarChar).Value
= TextBox1.Text
DBCmd.Parameters.Add("@AUTHOR",
Data.SqlDbType.VarChar).Value = TextBox2.Text
DBCmd.Parameters.Add("@PUBLISHER",
Data.SqlDbType.VarChar).Value = TextBox3.Text
DBCmd.ExecuteNonQuery()
Label11.Text = "You have added the '" &
TextBox1.Text.ToString & "' book."
DBAdap = New Data.SqlClient.SqlDataAdapter("SELECT * FROM
BOOK", DBConn)
DBAdap.Fill(DS)
Catch ex As Exception
Label11.Text = "You were not able to add the '" &
TextBox1.Text.ToString & "' book."
End Try
DBCmd.Dispose()
DBAdap.Dispose()
DBConn.Close()
DBConn = Nothing
End Sub