How to put query in database?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cor

    #16
    Re: How to put query in database?

    Hi Wim,

    Can you only try this (I am not sure if it is direct the solution)
    But than we can see it it connects.[color=blue]
    > Dim connection1 As OleDb.OleDbConn ection = _[/color]
    New OleDb.OleDbConn ection(Connecti onstring)[color=blue]
    >
    > Dim command1 As OleDb.OleDbComm and = New OleDb.OleDbComm and("Select * from
    > import")[/color]
    -Delete rows above
    [color=blue]
    > command1.Comman dType = CommandType.Tex t[/color]
    -Delete row above
    dim conn as New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data
    Source=C:\backu p Compaq MV500\TAGS\Acce ss\2003.mdb;")
    Dim OleDbDataAdapte r1 As OleDb.OleDbData Adapter = _
    New OleDb.OleDbData Adapter("Select * from import",conn)
    dim ds as new dataset
    Try
    OleDbDataAdapte r1.Fill(ds)[color=blue]
    >
    > connection1.Ope n()[/color]
    -Delete row above
    [color=blue]
    > Catch ex As Exception
    >
    > txtError.Text = ex.Message & vbCrLf
    >
    > txtError.Text = txtError.Text & ex.StackTrace
    >
    > End Try[/color]


    Comment

    • Wim

      #17
      Re: How to put query in database?

      Hi Cor,

      I tried this code and this didn't give any error's anymore......
      Do you now what was wrong? the conn.open? or the OleDbCommand?
      What to do to showthe dataset in Datagrid1 on the form?

      thanks,

      wim
      Private Sub btnDatabase_Cli ck(ByVal sender As System.Object, ByVal e As
      System.EventArg s) Handles btnDatabase.Cli ck

      'ds = New DataSet("import ")

      'Dim Connectionstrin g As String

      'Connectionstri ng = "Provider=Micro soft.Jet.OLEDB. 4.0;Password="" ;User
      ID=Admin;Data Source=C:\backu p Compaq MV500\TAGS\Acce ss\2003.mdb;Mod e=Share
      Deny None;Extended Properties="";J et OLEDB:System database="";Jet
      OLEDB:Registry Path="";Jet OLEDB:Database Password="";Jet OLEDB:Engine
      Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk
      Ops=2;Jet OLEDB:Global Bulk Transactions=1; Jet OLEDB:New Database
      Password="";Jet OLEDB:Create System Database=False; Jet OLEDB:Encrypt
      Database=False; Jet OLEDB:Don't Copy Locale on Compact=False;J et
      OLEDB:Compact Without Replica Repair=False;Je t OLEDB:SFP=False "

      'Dim connection1 As OleDbConnection = New OleDbConnection (Connectionstri ng)

      'Dim command1 As OleDbCommand = New OleDbCommand("S elect * from import")

      'command1.Comma ndType = CommandType.Tex t

      Dim conn As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data
      Source=C:\backu p Compaq MV500\TAGS\Acce ss\2003.mdb;")

      Dim oleDbDataAdapte r1 As OleDbDataAdapte r = New OleDbDataAdapte r("select *
      from import", conn)

      Dim ds As New DataSet()

      Try

      oledbdataadapte r1.Fill(ds)

      'conn.Open()

      Catch ex As Exception

      txtError.Text = ex.Message & vbCrLf

      txtError.Text = txtError.Text & ex.StackTrace

      End Try

      'Try

      ' connection1.Ope n()

      'Catch ex As Exception

      ' txtError.Text = ex.Message & vbCrLf

      ' txtError.Text = txtError.Text & ex.StackTrace

      'End Try

      'command1.Conne ction = connection1

      'Dim OleDbDataAdapte r1 As OleDb.OleDbData Adapter = New
      OleDb.OleDbData Adapter()

      'OleDbDataAdapt er1.SelectComma nd = command1

      'OleDbDataAdapt er1.TableMappin gs.Add("Table", "import")

      'OleDbDataAdapt er1.Fill(ds)

      'Dim datagrid1 As New DataGrid()

      'DataGrid1.SetD ataBinding(ds, "import")

      End Sub


      "Cor" <non@non.com> schreef in bericht
      news:e8CCgOB4DH A.2648@tk2msftn gp13.phx.gbl...[color=blue]
      > Hi Wim,
      >
      > Can you only try this (I am not sure if it is direct the solution)
      > But than we can see it it connects.[color=green]
      > > Dim connection1 As OleDb.OleDbConn ection = _[/color]
      > New OleDb.OleDbConn ection(Connecti onstring)[color=green]
      > >
      > > Dim command1 As OleDb.OleDbComm and = New OleDb.OleDbComm and("Select *[/color][/color]
      from[color=blue][color=green]
      > > import")[/color]
      > -Delete rows above
      >[color=green]
      > > command1.Comman dType = CommandType.Tex t[/color]
      > -Delete row above
      > dim conn as New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data
      > Source=C:\backu p Compaq MV500\TAGS\Acce ss\2003.mdb;")
      > Dim OleDbDataAdapte r1 As OleDb.OleDbData Adapter = _
      > New OleDb.OleDbData Adapter("Select * from import",conn)
      > dim ds as new dataset
      > Try
      > OleDbDataAdapte r1.Fill(ds)[color=green]
      > >
      > > connection1.Ope n()[/color]
      > -Delete row above
      >[color=green]
      > > Catch ex As Exception
      > >
      > > txtError.Text = ex.Message & vbCrLf
      > >
      > > txtError.Text = txtError.Text & ex.StackTrace
      > >
      > > End Try[/color]
      >
      >[/color]


      Comment

      • Cor

        #18
        Re: How to put query in database?

        Hi Wim,

        I asume it is a winforms datagrid than just[color=blue]
        > 'OleDbDataAdapt er1.Fill(ds)
        > 'Dim datagrid1 As New DataGrid()
        > 'DataGrid1.SetD ataBinding(ds, "import")[/color]
        Replace row above by
        DataGrid1.datas ource =ds.tables(0)

        I hope this helps

        Cor


        Comment

        • Wim

          #19
          Re: How to put query in database?


          hi Cor,

          thanks this is working good!

          Now I need to find out how to copy records from 1 table (table import) to
          another table (table dummy) by a query.
          The second table must be cleared each time before I run the query.....

          The first table (import) has a field "time" and what I want is to select
          only those records between time1 and time2.

          If possible Time1 and Time2 are date variable that I can give a value by
          dtaepicker or textbox ...


          I'll buy second book special for ADO.NET because My VB.NET book learns me
          little about it..


          Thanks again for your help,

          Wim




          "Cor" <non@non.com> schreef in bericht
          news:OPVvt3B4DH A.2528@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Hi Wim,
          >
          > I asume it is a winforms datagrid than just[color=green]
          > > 'OleDbDataAdapt er1.Fill(ds)
          > > 'Dim datagrid1 As New DataGrid()
          > > 'DataGrid1.SetD ataBinding(ds, "import")[/color]
          > Replace row above by
          > DataGrid1.datas ource =ds.tables(0)
          >
          > I hope this helps
          >
          > Cor
          >
          >[/color]


          Comment

          Working...