从.NETQ请求VB.NET Access数据库 [英] VB.NET Access data base asking from LINQ

查看:114
本文介绍了从.NETQ请求VB.NET Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个程序,我有链接访问日期库(Samochody)。现在我尝试列出所有仅带有第一列宝马的汽车(名称:Marka)。我写了一些LINQ问题,但是我有一个问题,当我启动程序并单击按钮时,我看到:

I have a program where I have link Access datebase (Samochody). Right now I try to List all Cars with only BMW with first column (name: Marka). I write some LINQ ask but I have a problem, when I start a program and click button I see:


`类型'System.MissingMemberException的未处理异常'发生在Microsoft.VisualBasic.dll

`An unhandled exception of type 'System.MissingMemberException' occurred in Microsoft.VisualBasic.dll

其他信息:DataRowView没有公共模型。

Additional information: There is no public Model for DataRowView.`

我做了类似的事情:

         Dim test = From Samochody In SamochodyBindingSource Where_
Samochody.Model = "BMW" Order By Samochody.Model Select Samochody.Model
        Dim s As String = "Model"
        For Each Samochody In SamochodyBindingSource
        s &= Samochody.Model
        Next
        MessageBox.Show(s)

问题显示在行中:


s& = Samochody.Model

s &= Samochody.Model

你能给我一些线索或信息在哪里可以我找到这种数据排序方法的好手册?或者也许是关于如何制作类似内容的信息?

Could You give me some clue or information where can I find good manual for this type of data sorting method? Or perhaps information how I can make something similar?

推荐答案

你好,

我使用了一个用于论坛响应的现有项目,该项目从通过TableAdapter / BindingSource读取的修改后的Microsoft MS-Access NorthWind数据库中读取。

I took an existing project used for forum responses that reads from a modified Microsoft MS-Access NorthWind database read via TableAdapter/BindingSource.

为了灵活,我得到当前行然后,DataGridView中的国家/地区查询DataSet的数据而不是BindingSource,这比使用BindingSource更快。注意我使用的是Lambda而不是LINQ,其中Lambda是.NET从
LINQ和Lambda生成的,尽管不是SQLish是许多开发人员(包括我自己)在LINQ上的首选方法。

To be flexible I get the current row Country in the DataGridView then query the data for the DataSet rather than the BindingSource which is faster than with the BindingSource. Note I'm using Lambda rather than LINQ where Lambda is what .NET generates from LINQ and Lambda although not SQLish is the preferred method over LINQ by many developers including myself.

无论如何,在Lambda代码中,我将所有公司名称附加到StringBuilder,这比串联字符串更好。

Anyways in the Lambda code I append all company names to a StringBuilder which is better than concatenating string memory-wise.

Imports System.Text

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.OrdersTableAdapter.Fill(Me.NorthWindAzureDataSet.Orders)
        Me.CustomersTableAdapter.Fill(Me.NorthWindAzureDataSet.Customers)
    End Sub

    Private Sub CustomersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) _
        Handles CustomersBindingNavigatorSaveItem.Click

        Me.Validate()
        Me.CustomersBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.NorthWindAzureDataSet)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sb As New StringBuilder

        Dim currentCountry = CType(CustomersBindingSource.Current, DataRowView).
                Row.Field(Of String)("Country")

        sb.AppendLine(


" country for country {currentCountry} { Environment.NewLine}")
NorthWindAzureDataSet.Customers。
其中(Function(row)row.Country = currentCountry)。
选择(函数(行)row.CompanyName)。ToList()。ForEach(
Sub(compName)sb.AppendLine(compName))


MessageBox。 Show(sb.ToString())

End Sub
End Class
"Selected companies for country {currentCountry}{Environment.NewLine}") NorthWindAzureDataSet.Customers. Where(Function(row) row.Country = currentCountry). Select(Function(row) row.CompanyName).ToList().ForEach( Sub(compName) sb.AppendLine(compName)) MessageBox.Show(sb.ToString()) End Sub End Class

当然,您不必选择当前国家/地区,而只需在Samobody.Model中执行变量

Of course rather than selecting the current country you can simply do a variable as in Samobody.Model

以上代码的两个例子。

 


这篇关于从.NETQ请求VB.NET Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆