This forum is in permanent archive mode. Our new active community can be found here.

VB.net Converting Access 2005 Table to a Text file

edited April 2008 in Technology
What I am trying to accomplish is to convert what I type in on the Datagrid1 or textbox1-3 to text when the database table is updated. Then display that text file in the multi-line textbox3 above the datagrid and as far as displaying the text file I know how that is done. I want to do this either what I said before or to open the access file in my /bin folder that is updated when I press the update button. All I really need help with is the conversion. Here is what I have so far:


image


Imports System.data
Imports System.IO
Imports System.Data.OleDb


Public Class Form1
Private bindMgr As BindingManagerBase

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 'SurveyDataSet1.Survey' table. You can move, or remove it, as needed.
Me.SurveyTableAdapter.Fill(Me.SurveyDataSet1.Survey)
'TODO: This line of code loads data into the 'SurveyDataSet.Survey' table. You can move, or remove it, as needed.
Me.SurveyTableAdapter.Fill(Me.SurveyDataSet.Survey)
'TODO: This line of code loads data into the 'SurveyDataSet.Survey' table. You can move, or remove it, as needed.
bindMgr = MyBase.BindingContext(SurveyDataSet, "survey")
Me.SurveyTableAdapter.Fill(Me.SurveyDataSet.Survey)
'TODO: This line of code loads data into the 'SurveyDataSet.Survey' table. You can move, or remove it, as needed.
Me.SurveyTableAdapter.Fill(Me.SurveyDataSet.Survey)
'TODO: This line of code loads data into the 'SurveyDataSet.Survey' table. You can move, or remove it, as needed.
Me.SurveyTableAdapter.Fill(Me.SurveyDataSet.Survey)

End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Try
Me.SurveyBindingSource.EndEdit()
Me.SurveyTableAdapter.Update(Me.SurveyDataSet.Survey)
MessageBox.Show("Database was updated")
Me.SurveyTableAdapter.Fill(Me.SurveyDataSet.Survey)
Catch ex As Exception
MessageBox.Show("Problem updating database")
End Try


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bindMgr.Position -= 1
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
bindMgr.Position += 1
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
Me.BindingSource1.EndEdit()
Me.SurveyTableAdapter.Update(Me.SurveyDataSet.Survey)
MessageBox.Show("Database was updated")
Me.SurveyTableAdapter.Fill(Me.SurveyDataSet.Survey)
Catch ex As Exception
MessageBox.Show("Problem updating database")
End Try
End Sub

Private Sub TableLayoutPanel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

End Sub
End Class

Comments

  • Doesn't Microsoft Access let you export to CSV?
  • edited April 2008
    Yeah I wanted to do it via vb.net which only uses .mdb though. So when the table was updated the text file would update also when I use streamreader/writer.
    Post edited by Alan on
  • Yeah I wanted to do it via vb though so when the table was updated the text file would update also when I use streamreader/writer.
    This job is too big for Access. To have databases automatically do things when their tables are changed you need triggers. That means you need Oracle, MySQL 5, Postgres, etc. to do it the "right" way.

    Good luck dealing with Microsoft bs.
  • Why are you using Access? Is this a school project?
  • edited April 2008
    Yeah I wish there was a much simpler way to do this I may be able to do this with a datagrid but I'll have to look into that further and have it target a certain table.

    Yeah its a school project that I am trying to go a little further on but I hit a dead end. Were working with databases in VB.net and all I had to use Access for was to set up the table originally.

    Edit:
    Looks like I'm going to have to read up more on ADO I'll get back to you on this.
    Post edited by Alan on
  • My wife was taking a class on Access when I met her. Nasty stuff.
  • Looks like I'm going to have to read up more on ADOI'll get back to you on this.
    Be absolutely certain that you're reading the right documentation! The .NET architecture uses a massively different ADO framework than VBx did. When I was migrating from VB6 to VB 2008 I was hard pressed to find good documentation for ADO.NET that wasn't actually a mislabeled howto for ADO 2.x-3.x
Sign In or Register to comment.