vb.net - 从字符串“插入到reciptdetails(recip”到类型“integer”的转换无效)
问题描述
从数据库中获取recipt id
SQL = "select max(reciptid) as MAXID from recipts where 1"
Dim CMD2 As New OleDb.OleDbCommand
CMD2.Connection = MyConnection
CMD2.Transaction = MyTransaction
CMD2.CommandText = SQL
Dim ReciptID As Long = CMD2.ExecuteScalar()
CMD2.Dispose()
插入收据的详细信息
Dim I As Integer
For I = 0 To DataGridView2.Rows.Count - 1
'get the values first
Dim Barcode As String = DataGridView2.Rows(I).Cells(0).Value
Dim ItemBuyPrice As Decimal = DataGridView2.Rows(I).Cells(2).Value
Dim ItemSellPrice As Decimal = DataGridView2.Rows(I).Cells(3).Value
Dim ItemCount As Integer = DataGridView2.Rows(I).Cells(4).Value
Dim CMD3 As New OleDb.OleDbCommand
SQL = "insert into reciptdetails (reciptid, barcode, itemcount, itembuyprice, itemsellprice) values (:0 ,:1 ,:2 ,:3 ,:4 )"
CMD3.Connection = MyConnection
CMD3.Transaction = MyTransaction
CMD3.CommandType = SQL
CMD3.Parameters.AddWithValue(":0", ReciptID)
CMD3.Parameters.AddWithValue(":1", Barcode)
CMD3.Parameters.AddWithValue(":2", ItemCount)
CMD3.Parameters.AddWithValue(":3", ItemBuyPrice)
CMD3.Parameters.AddWithValue(":4", ItemSellPrice)
CMD3.ExecuteNonQuery()
CMD3.Dispose()
查询有什么问题吗?
解决方案
这是你的错误:
CMD3.CommandType = SQL
OleDbCommand.CommandType
需要一个CommandType值,而不是一个字符串。
你可能打算写:
CMD3.CommandText = SQL
我强烈建议打开Option Strict
,它允许您在编译时而不是在运行时捕获此类错误。
推荐阅读
- python - 在销售订单列表视图中过滤订单参考范围?
- kubernetes - 只监控一个命名空间 pod - Prometheus & Kubernetes & cadvisor
- android - 使用 scaleType 设置窗口背景
- pandas - 我最近将 excel 工作簿转换为 csv 文件 (utf-8)。但是它没有被加载
- magento2 - 如何在 Magento2 的特定块中替换 Escaper 类
- c - 如何在 C 中修复“不兼容的整数到指针的转换”
- amazon-web-services - 从 DynamoDB 到 S3 的数据归档
- c# - C# 使用 4G Dongle APN 连接到移动网络
- r - 获取 R 包的描述/标题
- python - 未排序的二进制数组中第一次出现 1