sql从表中选择最大数量 [英] sql select max number from table

查看:64
本文介绍了sql从表中选择最大数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有tabe1包含column3,这是NVARCHAR



我需要在column3中选择最高的数字并在文本框中显示

解决方案

SQL查询:

从table1中选择MAX(Column3)



 DataTable table =  new  DataTable(); 
使用(SqlConnection connection = new SqlConnection( ConnectionString))
{
使用(SqlCommand cmd = new SqlCommand( 从table1中选择MAX(Column3) ,connection))
{
使用(SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
adapter.Fill(table);
textBox.Text = table.Rows [ 0 ]。ToString();
}
}
}





http://www.w3schools.com/sql/sql_func_max.asp [ ^ ]

http://www.tutorialspoint.com/sql/sql-max-function.htm [ ^ ]



使用C#连接和查询SQL数据库 [ ^ ]

https://msdn.microsoft.com/en-us /library/fksx3b4f.aspx [ ^ ]



-KR


SELECT MAX(COLUMN3)FROM TABLE1



如果列包含数字那么,它将显示最大数字

SqlConnection con = new SqlConnection(// Connectionpath);

SqlCommand cmd = new SqlCommand();

SqlDataAdapter ada = new SqlDataAdapter ();

DataTable dt = new Datatable();



cmd.Connection = con;

cmd .CommandText =SELECT MAX(COLUMN3)FROM TABLE1;

ada.SelectCommand = cmd;

ada.Fill(dt);



if(dt.Rows.Count> 0)

{

textBox.Text = dt.Rows [0] [COLUMN3] .ToString();

}


I have tabe1 contains column3 which is NVARCHAR

I need to select the highest number in column3 and show it in a textbox

解决方案

SQL Query:
select MAX(Column3) from table1

DataTable table = new DataTable();
using (SqlConnection connection = new SqlConnection("ConnectionString"))
{
    using (SqlCommand cmd = new SqlCommand("select MAX(Column3) from table1", connection))
    {
        using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
        {
            adapter.Fill(table);
            textBox.Text = table.Rows[0].ToString();
        }
    }
}



http://www.w3schools.com/sql/sql_func_max.asp[^]
http://www.tutorialspoint.com/sql/sql-max-function.htm[^]

Using C# to connect to and query from a SQL database[^]
https://msdn.microsoft.com/en-us/library/fksx3b4f.aspx[^]

-KR


SELECT MAX(COLUMN3) FROM TABLE1

IF THE COLUMN CONTAINS NUMBER THEN, IT WILL SHOW THE MAX NUMBER


SqlConnection con=new SqlConnection("//Connectionpath");
SqlCommand cmd=new SqlCommand();
SqlDataAdapter ada=new SqlDataAdapter();
DataTable dt=new Datatable();

cmd.Connection=con;
cmd.CommandText="SELECT MAX(COLUMN3) FROM TABLE1";
ada.SelectCommand=cmd;
ada.Fill(dt);

if(dt.Rows.Count>0)
{
textBox.Text = dt.Rows[0]["COLUMN3"].ToString();
}


这篇关于sql从表中选择最大数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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