Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. problem in updating database [modified]

problem in updating database [modified]

Scheduled Pinned Locked Moved Visual Basic
helpdatabaseannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rajulama
    wrote on last edited by
    #1

    Hi, I am having problem to update the database from the changes made to DGV. Following is the code and line in the bold doesn't update the database. Please help me

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'Db1DataSet.Sheet1' table. You can move, or remove it, as needed.
    Me.Sheet1TableAdapter.Fill(Me.Db1DataSet.Sheet1)

    End Sub
    
    Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
            Dim fi As New FileInfo(OpenFileDialog1.FileName)
            Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
            Dim objConn As New OleDbConnection(sConnectionString)
            Dim objDataSet As DataSet = New DataSet()
            objConn.Open()
            Dim objCmdSelect As New OleDbCommand("SELECT \* FROM " & fi.Name, objConn)
            Dim objAdapter1 As New OleDbDataAdapter
            objAdapter1.SelectCommand = objCmdSelect
            objAdapter1.Fill(objDataSet, "test")
            DataGridView1.DataSource = objDataSet.Tables(0).DefaultView
            objConn.Close()
           ** Me.Sheet1TableAdapter.Update(Me.Db1DataSet.Sheet1)**
        End If
        
    End Sub
    

    modified on Saturday, April 11, 2009 3:26 AM

    M 1 Reply Last reply
    0
    • R rajulama

      Hi, I am having problem to update the database from the changes made to DGV. Following is the code and line in the bold doesn't update the database. Please help me

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      'TODO: This line of code loads data into the 'Db1DataSet.Sheet1' table. You can move, or remove it, as needed.
      Me.Sheet1TableAdapter.Fill(Me.Db1DataSet.Sheet1)

      End Sub
      
      Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
              Dim fi As New FileInfo(OpenFileDialog1.FileName)
              Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
              Dim objConn As New OleDbConnection(sConnectionString)
              Dim objDataSet As DataSet = New DataSet()
              objConn.Open()
              Dim objCmdSelect As New OleDbCommand("SELECT \* FROM " & fi.Name, objConn)
              Dim objAdapter1 As New OleDbDataAdapter
              objAdapter1.SelectCommand = objCmdSelect
              objAdapter1.Fill(objDataSet, "test")
              DataGridView1.DataSource = objDataSet.Tables(0).DefaultView
              objConn.Close()
             ** Me.Sheet1TableAdapter.Update(Me.Db1DataSet.Sheet1)**
          End If
          
      End Sub
      

      modified on Saturday, April 11, 2009 3:26 AM

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      What sort of database, looks like an old DBF connection method. I suspect this has nothing to do with a database but is an attempt to read in excel files!

      Never underestimate the power of human stupidity RAH

      R 1 Reply Last reply
      0
      • M Mycroft Holmes

        What sort of database, looks like an old DBF connection method. I suspect this has nothing to do with a database but is an attempt to read in excel files!

        Never underestimate the power of human stupidity RAH

        R Offline
        R Offline
        rajulama
        wrote on last edited by
        #3

        its access database in addition to the csv file. Reading from csv file into DGV and updating an existing access database from that DGV. I hope I made it clear.

        D 1 Reply Last reply
        0
        • R rajulama

          its access database in addition to the csv file. Reading from csv file into DGV and updating an existing access database from that DGV. I hope I made it clear.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Well, I can tell your SQL statement is wrong. Your code says something like this:

          SELECT \* FROM C:\\folder\\somefile.mdf
          

          which will not work at all. You're trying to try a file path as a table in SQL. You have to provide a TABLE name in the database to the SQL statement, not a file path. Seriously, you're missing the very basic concepts of working with databases. I highly suggest picking up a book on VB.NET and ADO.NET and working through them.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups