110,539
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using MySQLDriverCS;
using System.Data.Odbc;
using System.Windows.Forms;
namespace PhotoApplication
{
class DatatBaseDeal
{
public DatatBaseDeal() { }
public int RunMySQL(string sql)
{
MySQLConnection conn = null;
MySQLCommand commn = null;
int data = 0;
try
{
conn = new MySQLConnection(new MySQLConnectionString("localhost", "photo", "root", "", 3309).AsString);
conn.Open();
commn = new MySQLCommand(sql, conn);
data = commn.ExecuteNonQuery();
MessageBox.Show(data.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
return data;
}
/// <summary>
/// 查询编号
/// </summary>
/// <returns></returns>
public Boolean selectGround(string str)
{
//string sql = "select '" + str + "' from ground";
string sql = "select count(ground_number) from ground where ground_number = 'aaa-11'";
int resultDeal = RunMySQL(sql);
if (resultDeal == 1)
{
return true;
}
else
{
return false;
}
}
}
}
using System.Data;
using System.Data.SqlClient;
namespace ExecuteScalar
{
class Program
{
static void Main(string[] args)
{
SqlConnection thisConnection = new SqlConnection(
@"Data Source=scott;Initial Catalog=northwind;Persist Security Info=True;User ID=sa;Password=sa123");
thisConnection.Open();
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "select count(*) from customers";
//ExecuteScalar:执行只返回一个值的SQL命令。
object countResult = thisCommand.ExecuteScalar();
Console.WriteLine("Count of Customers={0}",countResult);
Console.ReadLine();
thisConnection.Close();
}
}
}
data = commn.ExecuteNonQuery();