[英]vb.net query to display specific rows of datatable [basic]
如何在表查詢代碼中顯示查詢返回的特定行
SELECT name, STD, Fees, paid
FROM register
WHERE (paid - Fees < 0)
我收到錯誤
"An unhandled exception of type 'System.Data.ConstraintException'
occurred in System.Data.dll
Additional information: Failed to enable constraints. One or more rows
contain values violating non-null, unique, or foreign-key constraints."
但是,當我返回所有行時,它工作得很好我如何只顯示特定的行?
我用了
Dim test As DataTable
test = Me.RegisterTableAdapter.GetDataBy ' GetDataBy is Query
DataGridView1.DataSource = test
通過選擇表中的所有列來進行查詢。 如果省略查詢數據中的列,則TableAdapter會填充null。
SELECT student_id, name, contact_number, address, STD, FEES, Duration, image_lotacion, (....)
FROM register WHERE (paid - Fees < 0)
另一種選擇是允許DataTable接受空值而不會出錯。 在DataTable中每列的屬性中,將AllowDBNull屬性設置為True,將屬性NullValue設置為Empty,如果它是數值或布爾值,則設置為0。 您還應該刪除主鍵並允許列為零,因為如果不包含在辦公室中,也會給出錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.