2014-04-07 65 views
0

我已經創建了兩個日期時間選擇器的格式,並希望訪問從日期時間選擇器中選擇兩個特定日期之間存儲在Access數據庫中的數據訪問的數據庫中的數據。如何使用日期時間選擇器值使用VB.NET

可能有人請幫助如何處理該按鈕

objDoc = gobjGeoApp.document 
    Dim GeoApp As GeoMedia.Application 
    GeoApp = gobjGeoApp 
    objDoc.Close() 

    GeoApp.Open("C:\GeoWorkspaces\PowerPOCfinal.gws") 

    objDoc.Connections.Add("Connect1") 

    With objDoc.Connections.item(1) 
     .Location = "C:\Warehouses\prjct_mntrng.mdb" 

     .Description = "PM Data" 
     .Mode = PClient.ConnectionConstants.gmcModeReadWrite 
     .Type = "Access.GDatabase" 
     .Connect() 
    End With 

    With ListBox1 
     .Items.Add("Full Name = " & objDoc.Connections(1).Name) 
     .Items.Add("Name = " & objDoc.Name) 
     .Items.Add("Path = " & objDoc.Path) 
     .Items.Add("Storage = " & objDoc.Storage) 
    End With 

End Sub 


Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 

    ' Create and display recordset of Actual Start 
    objConnect = objDoc.Connections.item(1) 
    objConnect.CreateOriginatingPipe(objOPipe1) 

    With objOPipe1 
     .GeometryFieldName = "Geometry" 
     .Table = "Electric_Cables" 
     .Filter = "((Electric_Cables.Actual_Start)<=" + DateTimePicker1.Value.Date() + " And (Electric_Cables.Actual_Start)<=" + DateTimePicker2.Value.Date() + ")" 
     objRS = objOPipe1.OutputRecordset 
     objRS.MoveLast() 
     objRS.MoveFirst() 
     MsgBox(objOPipe1.OutputRecordset.RecordCount) 

    End With 
End Sub 
+0

你知道如何從vb.net連接到數據庫? – Baby

回答

0

的點擊按鈕單擊這麼做,我只是將數據綁定在GridView控件按您的要求在DataSet中

使用數據
Dim connection As SqlConnection = New sqlconnection() 
    connection.ConnectionString = "YOUR CONNECTION STRING" 
    connection.Open() 
    Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from Table where Date between DateTimePicker1.Value and DateTimePicker2.Value", connection) 
    Dim ds As DataSet = New DataSet() 
    adp.Fill(ds) 
    DataGridView1.DataSource = ds.Tables(0) 
+0

我訪問數據庫,因此暗淡連接,SqlConnection的給予和error.please幫助,我也想顯示在listbox..can retireived數據u請建議如何進行 – Rajat

+0

是它在運行時或complie時間 – KarthikManoharan

+0

編譯時錯誤和錯誤是「類型的SQL連接沒有定義。和我已經連接到數據庫,然後我可以導入使新coonection – Rajat

0

您將需要與SQL語句的其它部分來連接從控制值,就像這樣:

"select * from Table where Date between" + DateTimePicker1.SelectedDate.ToString() + " and " + DateTimePicker2.SelectedDate.ToString() 

你也可以考慮只增加一個ASP的SqlDataSource,它會是這樣的:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT [ID], [mydt], [Field1] FROM [Table1] WHERE (([mydt] &gt;= ?) AND ([mydt] &lt;= ?))"> 
      <SelectParameters> 
       <asp:ControlParameter ControlID="Calendar1" Name="mydt" PropertyName="SelectedDate" Type="DateTime" /> 
       <asp:ControlParameter ControlID="Calendar2" Name="mydt2" PropertyName="SelectedDate" Type="DateTime" /> 
      </SelectParameters> 
     </asp:SqlDataSource> 
相關問題