更新Datagridview数据 - 查询 [英] Update Datagridview Data - Query

查看:65
本文介绍了更新Datagridview数据 - 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我希望有人可以提供帮助,因为我正在尝试建立是否需要在此项目中包含mysql或msaccess数据库。

I hope someone can provide assistance, as i'm trying to establish if need to include a mysql or msaccess database to this project.

我有两种窗体形式如下:

I have two windows forms as follows:

#1

Imports System.Data.DataTable
Imports System.IO
Imports Microsoft.Office.Interop
Public Class Form1
    Dim table As New DataTable("table")
    Dim Employee As String
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        table.Columns.Add("Employee Name", Type.GetType("System.String"))
        table.Columns.Add("Payroll Number", Type.GetType("System.String"))
        table.Columns.Add("Job Title", Type.GetType("System.String"))
        table.Columns.Add("Site/Department", Type.GetType("System.String"))
        table.Columns.Add("Payrise", Type.GetType("System.String"))
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        table.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text)
        Form2.DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader
        Form2.DataGridView1.RowTemplate.Height = 50
        Form2.DataGridView1.AllowUserToAddRows = False
        Form2.DataGridView1.DataSource = table
        MessageBox.Show("Saved Successfully")
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.Hide()
        Form2.SHow()
    End Sub
End Class

#2

Public Class Form2

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Application.Exit()
        End
    End Sub

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class

现在,我的查询如下。如果我在form1上,例如,我插入数据3个别实例并继续执行表格2,它会在form2上显示的datagridview上创建3个单独的行。

Now, my query is as follows. If i'm on form1 and for example, i insert data 3 individual instances and proceed to form 2 it creates 3 individual rows on the datagridview shown on form2.

有谁知道如何在datagridview中选择一行,然后点击如果我希望给他们加薪或者不使用单选按钮更新该特定行列而不覆盖显示的所有数据? 

Does anyone have any idea how i can select a row in the datagridview, and click if i wish to give them a pay rise or not using the radio button to update that specific row column without overwriting all the data shown? 

我不知道我是否需要使用MSAccess / Mysaql数据库。

I don't know if i need to use a MSAccess / Mysaql database.

任何指导都将不胜感激! 

Any guidance would be appreciated! 

推荐答案

是否使用Access或SQL取决于应用程序体系结构和数据库大小。

Whether you use Access or SQL depends on the application architecture and database size.

如果其中任何一个为真:

If any of these are true:


  • 多个用户将访问数据
  • 将会有大量创建新记录并删除旧记录或未使用记录
  • 数据将是我以GB为单位而不是以兆字节为单位

然后你绝对应该使用SQL。 除非使用Access有其他好处,否则最好使用SQL而不管上述几点。

Then you should definitely use SQL.  Unless there is some other benefit to using Access, it may be best to use SQL regardless of the above points.

至于第二个问题,你可以为Update按钮的click事件编写代码处理程序,查看RadioButton的Checked状态,然后显示另一个表单或输入框以获取用户的工资率调整金额,修改
的值,为该BindingSource使用的当前行的相应字段DataGridView并最终对数据库执行Update命令以保持新的工资率值。

As for your second question, you would write code for the Update button's click event handler to look at the Checked state of the RadioButton and then show another form or input box to get the pay rate adjustment amount from the user, modify the value of the appropriate field for the current row in the BindingSource used by that DataGridView and finally execute an Update command against the database to persist the new pay rate value.

确切的编码将由您选择的数据库和您设计的接口来确定费率变动金额。

The exact coding will be determined by your choice of database and by the interface you design to capture the pay rate change amount.


这篇关于更新Datagridview数据 - 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆