【发布时间】:2017-04-06 08:36:54
【问题描述】:
早上好,我正在开发一个代码,可以让我在 sql 中退出我的数据库,即某个列的 AVG。 问题是我没有得到它,我认为问题是查询但我不知道如何解决它。 我需要帮助,谢谢。
代码如下:
String connectionString =
"Data Source=localhost;" +
"Initial Catalog=DB_SACC;" +
"User id=sa;" +
"Password=1234;";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
string textt = " USE [DB_SACC] SELECT AVG (Total_Divida) FROM t_pagamentos";
cmd.CommandText = textt;
connection.Open();
cmd.Connection = connection;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
if (textt == null)
{
MessageBox.Show("nothing");
}
else
{
TextBox3.Text = textt;
}
【问题讨论】:
-
提示:你正在使用
cmd.ExecuteNonQuery()执行查询 -
使用
ExecuteScalar()将其输出存储在某个对象中,然后访问它 -
AVG不需要GROUP BY吗? -
我在文本框中放了什么?返回查询值!
标签: c# asp.net sql-server