using System;
using MySql.Data.MySqlClient;
class Program
{
static void Main(string[] args)
{
string connectionString = "server=localhost;user=root;database=your_database;password=your_password";
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
string columnName = "your_column";
string tableName = "your_table";
string query = $"SELECT MAX({columnName}) FROM {tableName}";
using (MySqlCommand command = new MySqlCommand(query, connection))
{
object result = command.ExecuteScalar();
if (result != null && result != DBNull.Value)
{
Console.WriteLine($"Max value of {columnName}: {result}");
}
else
{
Console.WriteLine("No data found.");
}
}
}
}
}
c# 计算MySQL表中一列的最大值
最新推荐文章于 2024-08-30 14:28:14 发布