Share save button code in vb.net using access,

duongguitar1

New member
#savebuttoncode #vb.net #Access #database #Programming ** Lưu mã nút trong VB.NET bằng cách sử dụng Access **

Bài viết này sẽ chỉ cho bạn cách tạo nút lưu trong VB.NET bằng cách sử dụng Access.Nút lưu sẽ lưu bản ghi hiện tại trong cơ sở dữ liệu.

## 1. Tạo một dự án mới

Để bắt đầu, mở Visual Studio và tạo một dự án mới.Chọn ** Tệp **> ** Mới **> ** Dự án **.Trong hộp thoại ** New Project **, chọn ** Visual Basic **> ** Ứng dụng Windows Forms **.Kể tên dự án ** SaveButton ** và nhấp vào ** OK **.

## 2. Thêm một biểu mẫu vào dự án

Một biểu mẫu sẽ được tạo tự động khi bạn tạo dự án ứng dụng Windows Forms mới.Bạn có thể đổi tên biểu mẫu bằng cách nhấp đúp vào tên của nó trong cửa sổ ** Solution Explorer **.

## 3. Thêm điều khiển hộp văn bản vào biểu mẫu

Một điều khiển hộp văn bản được sử dụng để hiển thị văn bản.Để thêm điều khiển hộp văn bản vào biểu mẫu, kéo và thả điều khiển hộp văn bản từ cửa sổ Hộp công cụ ** ** vào biểu mẫu.

## 4. Thêm nút lưu vào biểu mẫu

Một nút lưu được sử dụng để lưu bản ghi hiện tại trong cơ sở dữ liệu.Để thêm nút lưu vào biểu mẫu, kéo và thả điều khiển nút từ cửa sổ ** Hộp công cụ ** vào biểu mẫu.

## 5. Đặt trình xử lý sự kiện nhấp vào nút Lưu của

Trình xử lý sự kiện nhấp được gọi khi người dùng nhấp vào nút Lưu.Để đặt trình xử lý sự kiện nhấp vào nút Lưu, nhấp đúp vào nút Lưu trong chế độ xem ** Thiết kế **.Điều này sẽ mở cửa sổ ** mã ** và tạo một trình xử lý sự kiện nhấp cho nút lưu.

## 6. Viết mã xử lý sự kiện nhấp vào nút Lưu của

Mã sau đây hiển thị mã xử lý sự kiện nhấp chuột cho nút lưu:

`` `VBNet
Sub Sub SaveButton_Click (Người gửi dưới dạng Đối tượng, E As As EventArgs) xử lý SaveButton.Click

'Nhận bản ghi hiện tại từ cơ sở dữ liệu.
Dim currentRecord dưới dạng dataset = me.bindingingource.current

'Lưu bản ghi hiện tại vào cơ sở dữ liệu.
currentRecord.Update ()

'Đóng biểu mẫu.
Me.close ()

Kết thúc phụ
`` `

## 7. Chạy dự án

Để chạy dự án, nhấn ** F5 **.Biểu mẫu sẽ được hiển thị trong trình gỡ lỗi Visual Studio.Nhập một số dữ liệu vào điều khiển hộp văn bản và nhấp vào nút Lưu.Bản ghi hiện tại sẽ được lưu vào cơ sở dữ liệu và biểu mẫu sẽ được đóng lại.

## 8. Tài nguyên bổ sung

* [Hướng dẫn vb.net] (https://www.tutorialspoint.com/vbnet/index.htm)
* [Hướng dẫn truy cập] (https://www.tutorialspoint.com/access/index.htm)
* [Lập trình cơ sở dữ liệu] (https://www.tutorialspoint.com/database_programming/index.htm)

## 5 hashtags

* #Savebutton
* #vb.net
* #Truy cập
* #database
* #Programming
=======================================
#savebuttoncode #vb.net #Access #database #Programming **Save Button Code in VB.NET Using Access**

This article will show you how to create a Save button in VB.NET using Access. The Save button will save the current record in the database.

## 1. Create a New Project

To begin, open Visual Studio and create a new project. Select **File** > **New** > **Project**. In the **New Project** dialog box, select **Visual Basic** > **Windows Forms Application**. Name the project **SaveButton** and click **OK**.

## 2. Add a Form to the Project

A form will be created automatically when you create a new Windows Forms Application project. You can rename the form by double-clicking on its name in the **Solution Explorer** window.

## 3. Add a TextBox Control to the Form

A TextBox control is used to display text. To add a TextBox control to the form, drag and drop a TextBox control from the **Toolbox** window onto the form.

## 4. Add a Save Button to the Form

A Save button is used to save the current record in the database. To add a Save button to the form, drag and drop a Button control from the **Toolbox** window onto the form.

## 5. Set the Save Button's Click Event Handler

The Click event handler is called when the user clicks the Save button. To set the Save button's Click event handler, double-click on the Save button in the **Design** view. This will open the **Code** window and create a Click event handler for the Save button.

## 6. Write the Save Button's Click Event Handler Code

The following code shows the Click event handler code for the Save button:

```vbnet
Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click

' Get the current record from the database.
Dim currentRecord As DataSet = Me.BindingSource.Current

' Save the current record to the database.
currentRecord.Update()

' Close the form.
Me.Close()

End Sub
```

## 7. Run the Project

To run the project, press **F5**. The form will be displayed in the Visual Studio debugger. Enter some data into the TextBox control and click the Save button. The current record will be saved to the database and the form will be closed.

## 8. Additional Resources

* [VB.NET Tutorials](https://www.tutorialspoint.com/vbnet/index.htm)
* [Access Tutorials](https://www.tutorialspoint.com/access/index.htm)
* [Database Programming](https://www.tutorialspoint.com/database_programming/index.htm)

## 5 Hashtags

* #Savebutton
* #vb.net
* #Access
* #database
* #Programming
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top