首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

! datagridview更新有关问题

2012-01-05 
在线等!急!急!急! datagridview更新问题Dim conn As SqlConnection New SqlConnectionconn.ConnectionSt

在线等!急!急!急! datagridview更新问题
Dim conn As SqlConnection = New SqlConnection
  conn.ConnectionString = connectionString
  Dim sql1, sql2 As String
  sql1 = "select * from codetype where typeid like '" & TextBox2.Text & "%'"
  sql2 = "select * from codeitem where typeid like '" & TextBox2.Text & "%'"


  Dim data As New DataSet()
  'data.Locale = System.Globalization.CultureInfo.InvariantCulture

  Dim masterDataAdapter As New SqlDataAdapter()
  masterDataAdapter.SelectCommand = New SqlCommand(sql1, conn)
  Dim cb1 As SqlCommandBuilder = New SqlCommandBuilder(masterDataAdapter)
  masterDataAdapter.Fill(data, "codetype")


  Dim detailsDataAdapter As New SqlDataAdapter()
  detailsDataAdapter.SelectCommand = New SqlCommand(sql2, conn)
  Dim cb2 As SqlCommandBuilder = New SqlCommandBuilder(detailsDataAdapter)
  detailsDataAdapter.Fill(data, "codeitem")
   

  masterDataAdapter.Update(data, "codetype")
  detailsDataAdapter.Update(data, "codeitem")
  data.AcceptChanges()
  'If data.HasChanges Then


   
  'data.Tables(1).AcceptChanges() 
  ' End If

  Dim parentCol As DataColumn
  Dim childCol As DataColumn

  parentCol = data.Tables("codetype").Columns("typeid")
  childCol = data.Tables("codeitem").Columns("typeid")

  Dim relation As New DataRelation("typeitem", _
  data.Tables("codetype").Columns("TypeID"), _
  data.Tables("codeItem").Columns("TypeID"))
  data.Relations.Add(relation)

   



  masterBindingSource.ResetBindings(False)
  detailsBindingSource.ResetBindings(False)


  masterBindingSource.DataSource = data
  masterBindingSource.DataMember = "codetype"


  detailsBindingSource.DataSource = masterBindingSource
  detailsBindingSource.DataMember = "typeitem"

  Me.DataGridView2.DataSource = masterBindingSource
  Me.DataGridView1.DataSource = detailsBindingSource

这是我写在"更新"按钮下的代码,为什么数据库更新不了啊?
大侠们帮帮忙啊!

[解决办法]
好像要加上这一句哟:detailsDataAdapter.UpdateCommand=cb2.GetUpdateCommand
[解决办法]
MARK,这个问题我也遇到了

热点排行