回答
为什么要将数据集用于单个静态值。如果您使用的是SQL读者使用的ExecuteScalar功能
例子:
function GetIntValue()
{
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["con"]);
con.Open();
SqlCommand cmdCount = new SqlCommand("SELECT COUNT(*) FROM Employees",con);
int numberOfEmployees = (int)cmdCount.ExecuteScalar();
Response.Write("Here are the " + numberOfEmployees.ToString() + " employees: <br><br>");
SqlCommand cmd = new SqlCommand("SELECT * FROM Employees",con);
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read()) {
Response.Write(dr["LastName"] + "<br>");
}
con.Close();
}
对不起,我不明白答案。 我做了一个函数返回我1行1点的值在那里,我想这样做someing像 textbox1.text =()的函数。的GetData 我该怎么办呢? – ShmuelCohen 2013-03-01 17:59:34
请参阅此示例http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx – SP007 2013-03-01 18:00:54
@ user2120874而不是将函数读入DataSet中,请使用ExecuteScalar()作为引用上面将函数结果直接读入一个变量。 – 2013-03-01 18:01:15
- 1. 从C++中读取int值向量
- 2. 从数据集中读取
- 3. 如何从文本文件读取int数组,在c + +中?
- 4. 如何读取plist数据并从中获取int?
- 5. 如何从OutputStreamWriter读取int?
- 6. 从数据集的数据表中读取值
- 7. 从数据库表中读取集合
- 8. 从C#读取Excel数据#
- 9. 如何在Objective-C中从HTML读取JSON-LD数据?
- 10. 如何在C#中从POST数据读取文件
- 11. 如何加速从oracle数据库中读取数据到pentaho数据集成?
- 12. Openpyxl - 如何从excel文件中的单元格读取int值
- 13. iOS如何从数组中读取值
- 14. 如何从javascript函数中读取值?
- 15. 从数据集中读取错误的值
- 16. 如何将数据从CSV读取到集合中
- 17. 从文件中读取int
- 18. 如何从int中除去值? C#
- 19. 如何读取SAS数据集?
- 20. Android SQLiteDataBase:如何读取数据集?
- 21. 从字典数组中读取int(NSCFNumber)
- 22. 读取数据从XLSX在C#
- 23. WPF,从C#中的XmlDataProvider读取数据#
- 24. 从文件中读取数据C
- 25. 从C++中的磁盘读取数据
- 26. 如何从mp3中读取元数据?
- 27. 如何从Json fromat中读取数据?
- 28. 如何从XNode中读取数据
- 29. 如何从sqlite表中读取数据?
- 30. 如何从C#中的(Google.Apis.Drive.v3.Data.File)中读取数据?
[C#ADO.NET的OleDbCommand - 的ExecuteScalar(http://csharp.net-informations.com/data-providers/csharp-oledbcommand -executescalar.htm) – 2013-03-01 17:52:53