阅读的SqlCommand一个值 [英] SqlCommand read one value

查看:136
本文介绍了阅读的SqlCommand一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从的SqlCommand 返回值的问题,我有这样的代码:

I have a problem with the value returned from SqlCommand, I have this code:

string sqlSelect = "Select TOP 1 Quotation.SentToSupp as SentToSupp FROM Quotation JOIN Notifications ON Quotation.QuotationId = QuotationID ";

SqlCommand Comm = new SqlCommand(sqlSelect, this.Connection);



的SQLSelect 查询选择第一个的DateTime 值。当我打电话给的SqlCommand 我要得到这个值(只有一个值)。我想补充的查询和我的连接罚款。

sqlSelect query selects the first DateTime value. When I call to SqlCommand I want to get this value (just one value). I add the query and my connection fine.

但我不知道如何让我的的DateTime 值。 ..一定要使用类似的ExecuteReader

But I don't know how to get my DateTime value... Must to use something like ExecuteReader?

感谢你在前进!

推荐答案

使用SqlCommand.ExecuteScalar方法 - 执行查询,并在该查询返回的结果集返回第一行的第一列。其他列或行被忽略。

Use SqlCommand.ExecuteScalar method - 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.

这篇关于阅读的SqlCommand一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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