在文本框中显示SQL Server 2016查询结果 [英] display sql server 2016 query result in a textbox

查看:243
本文介绍了在文本框中显示SQL Server 2016查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vb net接口创建sql server 2016数据库.

我想在文本框中显示行数. sql查询结果很简单,但是我不知道如何在文本框中显示标量查询结果,

任何想法

解决方案

你好,

使用SqlClient命令,按定义ExecuteScalar

执行查询,并返回查询返回的结果集中第一行的第一列.其他列或行将被忽略.

这样,如果项目是Integer,则将其强制转换为Integer,如果字符串是通过.ToString或CStr强制转换为字符串.

一个常见的示例是在对表执行INSERT之后获取新的主键,如下所示.请注意,首先有一个ExecuteNonQuery,然后是ExecuteScalar.

https://msdn. microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar(v=vs.110).aspx


Hi

I'm creating an sql server 2016 database with a vb net interface.

I would like to display the number of rows in a textbox. The sql query result is simple, but i dont know how to display the scalar query result in a text box,

any ideas

解决方案

Hello,

Using SqlClient command, ExecuteScalar by definition 

Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

With that, if the item is an Integer we cast it to an Integer, if a string cast to a string via .ToString or CStr.

A common example is to get the new primary key after executing a INSERT into a table as shown below. Note first there is an ExecuteNonQuery then ExecuteScalar.

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar(v=vs.110).aspx


这篇关于在文本框中显示SQL Server 2016查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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