Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub insert_category()
- Call connection_string()
- MysqlConn.Open()
- Query = "SELECT * FROM tbl_categories WHERE CategoryName = @CategoryName"
- COMMAND = New MySqlCommand(Query, MysqlConn)
- COMMAND.Parameters.AddWithValue("@CategoryName", txtCategoryName.Text)
- READER = COMMAND.ExecuteReader
- If READER.HasRows Then
- 'category already exists
- MsgBox(txtCategoryName.Text & " " & "already exist.Enter another name and try again", MsgBoxStyle.Exclamation, "Product")
- MysqlConn.Close()
- Else
- Try
- Call connection_string()
- MysqlConn.Open()
- Query = "INSERT INTO tbl_categories (CategoryName) VALUES (@CategoryCode,@CategoryName,@Datecreated,@status)"
- COMMAND = New MySqlCommand(Query, MysqlConn)
- COMMAND.Parameters.AddWithValue("@CategoryName", txtCategoryName.Text)
- READER = COMMAND.ExecuteReader
- MysqlConn.Close()
- MsgBox(txtCategoryName.Text & " " & "added successfully!", MsgBoxStyle.Information, "Success")
- txtCategoryName.Text = ""
- txtCategoryName.Focus()
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End If
- End Sub
Add Comment
Please, Sign In to add comment