从数组上的存储查询中填充datagridview

时间:2013-05-13 05:30:48

标签: arrays vb.net datagridview datacontext

我希望你能帮助我。我会尽可能准确。这是我的代码:

Dim productoArray = New List(Of Products)() ' <-- global

' --button method---
Dim db2 As New ConeccionANextelDataContext
    Dim [produ] As Product = db2.Products.SingleOrDefault(Function(x) x.Product_ID = Integer.Parse(IDProduct.Text.Trim()))

    If [produ] IsNot Nothing Then
        productoArray.add([produ])
        showBill.DataSource = vbNull
        showBill.DataSource = productoArray
        showTotalBill.Text = productoArray.Sum(Function(x) x.Price).ToString()
    Else
        MessageBox.Show("Product ID doesn't exits")
    End If

我正在尝试对DataGridView内容进行计费。我正在做的是声明一个Products(linq datacontext)类型的数组,在声明该数组之后我使用“过滤器”将产品添加到我的DataGridView,逐个使用Product_ID,但是当我执行并按下相应的按钮,它给我以下错误:

“指定的演员表无效。”就在这一行

Dim [produ] As Producto = db2.Products.SingleOrDefault(Function(x) x.Product_ID = Integer.Parse(IDProduct.Text.Trim()))

异常代码:

    System.InvalidCastException was unhandled
  Message=La conversión especificada no es válida.
  Source=System.Data.Linq
  StackTrace:
       en System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
       en System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
       en System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
       en System.Data.Linq.Table`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
       en System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
       en nextel_alpha.Form1.LAgrearVenta_Click(Object sender, EventArgs e) en C:\Users\Be\Desktop\preview\nextel alpha\nextel alpha\Form1.vb:línea 2044
       en System.Windows.Forms.Control.OnClick(EventArgs e)
       en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       en System.Windows.Forms.Control.WndProc(Message& m)
       en System.Windows.Forms.Label.WndProc(Message& m)
       en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       en System.Windows.Forms.Application.Run(ApplicationContext context)
       en Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       en Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       en Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       en nextel_alpha.My.MyApplication.Main(String[] Args) en 17d14f5c-a337-4978-8281-53493378c1071.vb:línea 81
       en System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       en System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       en Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       en System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       en System.Threading.ThreadHelper.ThreadStart()
  InnerException:

这不是我的所有代码,而是问题

¡¡¡¡EDIT !!!!

我发现问题是由于产品表中的BD我有钱型列... 无论如何问题仍然存在,因为我不知道为什么会这样,你,你 我试过其他表这样的客户端只有id为int,name为string,phone为string,没有问题。

0 个答案:

没有答案