I am writing a code that calls a column from a dataset using a SQL query. I use two parameters to identify which rows to select. One is the ProductSerialNumber, and the other is a datetimestamp. See my SQL query below
我正在编写一个代码,使用SQL查询从数据集中调用列。我使用两个参数来标识要选择的行。一个是ProductSerialNumber,另一个是datetimestamp。请参阅下面的SQL查询
Select TestStation FROM tblData
WHERE ProductSerialNumber = ? AND Datetimestamp = ?
In the dataset's datatable the productserialnumber is formatted as text, and the other is formatted as a date (as you would expect).
在数据集的数据表中,productserialnumber被格式化为文本,另一个被格式化为日期(正如您所期望的那样)。
In my vb.net code, I grab the Datetimestamp from another source (don't ask why, the only thing you need to know is that it grabs a valid datetimestamp, dimensioned as a date, that matches exactly with the tblData's entry) and I use the premade query to generate a datatable. The query is a Fill query called "TestStationLookUp"
在我的vb.net代码中,我从另一个源获取Datetimestamp(不要问为什么,你唯一需要知道的是它抓取一个有效的datetimestamp,标注为日期,与tblData的条目完全匹配)和我使用预制查询生成数据表。该查询是一个名为“TestStationLookUp”的填充查询
my vb.net code looks like this
我的vb.net代码看起来像这样
Dim dt as new dataset.tbldataDataTable
Dim dta As New DataSetTableAdapters.tbldataTableAdapter
Dim ProductSerialNumber as string = "XXXXXX"
Dim DateTimeStamp as date = SomeDateVariable
dta.TestStationLookUp(dt, ProductSerialNumber, DateTimeStamp)
It is here that the code tells me:
代码在这里告诉我:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Line 7366: dataTable.Clear
Line 7367: End If
Error: Line 7368: Dim returnValue As Integer = Me.Adapter.Fill(dataTable)
Line 7369: Return returnValue
Line 7370: End Function
I cannot understand why this error arises, as everything is dimensioned the way it should be. This exact code setup works elsewhere in my code (except it doesn't use a date), but this specific piece won't work.
我无法理解为什么会出现这种错误,因为一切都按照应有的方式确定。这个确切的代码设置在我的代码中的其他地方工作(除了它不使用日期),但这个特定的部分将不起作用。
Also, if I go to the dataset in my solution, I can use the "preview data" on this query and type in the EXACT same parameters (the ProductSerialNumber and DateTimeStamp that match the record in the table AND what I use in my vb code) and it will give me produce the table I want.
另外,如果我在我的解决方案中转到数据集,我可以在此查询中使用“预览数据”并输入EXACT相同的参数(与表中记录匹配的ProductSerialNumber和DateTimeStamp以及我在vb代码中使用的内容) )它会让我生产出我想要的桌子。
Can anyone assist?
有人可以帮忙吗?
1 个解决方案
#1
1
This error means that you are trying to access not valid unique id "ProductSerialNumber", maybe it does not exist
此错误意味着您尝试访问无效的唯一ID“ProductSerialNumber”,可能它不存在
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
无法启用约束。一行或多行包含违反非null,唯一或外键约束的值。
Instead of passing the variable that comes from dataset ,pass a valid number that you are sure it exists in database
不是传递来自数据集的变量,而是传递一个您确定它存在于数据库中的有效数字
#1
1
This error means that you are trying to access not valid unique id "ProductSerialNumber", maybe it does not exist
此错误意味着您尝试访问无效的唯一ID“ProductSerialNumber”,可能它不存在
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
无法启用约束。一行或多行包含违反非null,唯一或外键约束的值。
Instead of passing the variable that comes from dataset ,pass a valid number that you are sure it exists in database
不是传递来自数据集的变量,而是传递一个您确定它存在于数据库中的有效数字