判断DataGridView标题是否为某表中的字段
目前电子表格导入到DataGridView, 同时该表数据保存到对应的SQL数据库中,怕导入模版的表头有人改动,选判断DataGridView标题是否为对应表的字段。这样如何判断。Me.DataGridView1.DataSource = ds.Tables("ex")
Call cn_sql()
sqlstr = "select * from t_gpicc_gz "
sqladp = New SqlDataAdapter(sqlstr, conn)
cmdb = New SqlCommandBuilder(sqladp)
Dim ds1 As DataSet = New DataSet
sqladp.Fill(ds1, "t_gpicc_gz")
Dim dg As DataGridView = DataGridView1
For ri = 0 To dg.RowCount - 2
newrow = ds1.Tables("t_gpicc_gz").NewRow()
For ci = 0 To dg.ColumnCount - 1
If dg.Columns(ci).Visible = True Then
Dim hename = dg.Columns(ci).HeaderText.Trim.ToString ’DataGridViews标题
newrow(hename) = dg.Rows(ri).Cells(ci).Value '对应表添加数据,想在这儿判断一下,是否为该表字段
' MsgBox(ds.Tables("t_gpicc_gz").Rows(ri)(ci))
End If
Next
ds1.Tables("t_gpicc_gz").Rows.Add(newrow)