直接甩干货 控制台应用程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using MySql.Data.MySqlClient;
namespace ConsoleApplication3
{
class Program
{
private static MySqlConnection connectDataBase()
{
string str = "Server=12*.11*.2*.*;User ID=*u*h*ng;Password=y*u*h*ng**;Database=yo*s*a*g;CharSet=utf8;convert zero datetime=True;";
MySqlConnection conn = new MySqlConnection(str);
return conn;
}//end connectDataBase()
static void Main(string[] args)
{
// Connect to the master database and create the sample database
using (MySqlConnection conn = connectDataBase())
{
conn.Open();
//查询
using (MySqlCommand querySingleInfo = conn.CreateCommand())
{
querySingleInfo.CommandText = "select business_category from multi_config where id=1 ";
using (MySqlDataReader reader = querySingleInfo.ExecuteReader())
{
// Loop over the results
while (reader.Read())
{
Console.WriteLine(reader["business_category"].ToString().Trim());
// Console.ReadKey();
}
}
}
///更新 添加 删除
using (MySqlCommand myCommand = conn.CreateCommand())
{
myCommand.Connection = conn;
myCommand.CommandText = "update multi_config set service_status=-1 where id=10";
int ans = myCommand.ExecuteNonQuery();
Console.WriteLine(ans);
Console.ReadKey();
}
}
}//end Main()
}//end class Program
}