什么是值cmd.ExecuteScalar() [英] what is the value cmd.ExecuteScalar()

查看:199
本文介绍了什么是值cmd.ExecuteScalar()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



将是什么输出。我执行cmd时执行0或1

.ExecuteScalar()

Hello,

What will be the output. Either 0 or 1
when i executed cmd.ExecuteScalar()

推荐答案

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



请参阅: MSDN [ ^ ]


文档 [ ^ 清楚地说明:
执行查询,并返回查询返回的结果集中第一行的第一列。其他列或行将被忽略。
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.


好的,就这样:

Okay, just go like this :
var commandStr= "If not exists (select name from sysobjects where name = 'Customer') CREATE TABLE Customer(First_Name char(50),Last_Name char(50),Address char(50),City char(50),Country char(25),Birth_Date datetime)";

using (SqlCommand command = new SqlCommand(commandStr, con))
command.ExecuteNonQuery();


这篇关于什么是值cmd.ExecuteScalar()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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