毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> net技术 >> 正文

VB.net2008通过Gridview向Access数据库插入记录

更新时间:2012-5-25:  来源:毕业论文

Imports System.Data.OleDb
Public Class Form1
  Dim myconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Database1.mdb"
  Dim cn As OleDbConnection = New OleDbConnection(myconn)
  Private Dset As DataSet
  Dim ODA1 As OleDbDataAdapter

  Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

  MsgBox("确定要退出吗", MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "提示信息")

  End Sub
  

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim strsql As String

  Dim oda1 As New OleDbDataAdapter()


  cn.Open()

  Dim objDA As OleDbCommand = New OleDbCommand(strsql, cn)
  Console.Write(strsql)
  objDA.CommandText = "insert into [YLQWP] (ID,CTBH,LX) values('" & DataGridView1.Rows(0).Cells(0).Value & "','" & DataGridView1.Rows(0).Cells(1).Value & "','" & DataGridView1.Rows(0).Cells(2).Value & "')"
  objDA.ExecuteNonQuery()

  Dset = New DataSet()
  oda1.Fill(Dset)//报错点!!!错误为(在调用“Fill”前,SelectCommand 属性尚未初始化。)
  cn.Close()
  End Sub
请问给位高人如何解决这个问题~小弟苦思很久不得解决~跪求一良方~

SelectCommand 属性尚未初始化,没有语句啊,还有你的数据连接也没有看到啊!
Dim oda1 As New OleDbDataAdapter(“sql语句”,cn)
 
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim myconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data  Source=|DataDirectory|\Database1.mdb"
  Dim cn As OleDbConnection = New OleDbConnection(myconn)
  cn.open

  Dim strsql As String
  Dim OleCommand As OleDbCommand = New OleDbCommand
  OleCommand.Connection=Cn
  OleCommand.CommandText="select ID,CTBH,LX From YLQWP"
  Dim oda1 As New OleDbDataAdapter(OleCommand)
  Dset = New DataSet()
  oda1.Fill(Dset)
  cn.Close()
  DataGridView1.DataSource=Dset.table(0)
  End Sub

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。