vb.net查询以显示数据表的特定行[基本] [英] vb.net query to display specific rows of datatable [basic]

查看:169
本文介绍了vb.net查询以显示数据表的特定行[基本]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在表中显示查询返回的特定行 查询代码是

How do I display the specific rows returned by the query in a Table Query code is

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."

但是当我返回所有行时,它工作正常 如何仅显示特定行?

But when I return all rows it works fine How do I display only specific rows?

我用过

Dim test As DataTable
test = Me.RegisterTableAdapter.GetDataBy ' GetDataBy is Query    
DataGridView1.DataSource = test

推荐答案

通过选择表中的所有列进行查询.如果您省略查询数据中的列,则TableAdapter会填充null.

Make the query by selecting all the columns in the table. If you omit the columns in the query data TableAdapter populates null.

SELECT student_id, name, contact_number, address, STD, FEES, Duration, image_lotacion, (....) 
FROM  register WHERE (paid - Fees < 0)

另一个选择是允许DataTable接受空值且没有错误.在数据表中每列的属性中,将AllowDBNull属性设置为True,将属性NullValue设置为空,如果它是数字或布尔值,则将其设置为0.您还应该删除主键并允许该列为零,因为如果不包括在办公室中,也会产生错误.

Another option is to allow the DataTable accepts null values and no error. In the properties of each column in the DataTable, set the AllowDBNull property to True, and the property NullValue Empty or 0 if it is a numeric or Boolean value. You should also remove the primary key and allow the column is zero, because if not include in the office, also will give error.

这篇关于vb.net查询以显示数据表的特定行[基本]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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