C#内嵌sql语句的具体用法DataSet/MySqlDataReader类的使用

标签:
c内嵌sqlit |
分类: C# |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using System.IO;
namespace ConsoleApplication1
{
class
Program
{
public static bool RunCommand(MySqlCommand icmd, string
strCommend)
{
try
{
icmd.CommandText = strCommend;
icmd.ExecuteNonQuery();
}
catch (System.Exception e)
{
return false;
}
return true;
}
static void Main(string[] args)
{
string ConnectionString = "Database=test;Data Source=localhost;User
Id=root;Password=";//其中localhost表示连接本地数据库 改为相应的Id则可以实现远程连接
MySqlConnection dbconn = new
MySqlConnection(ConnectionString);//连接MySQL数据库
MySqlCommand cmd = dbconn.CreateCommand();
cmd.Connection.Open();
cmd.CommandType = CommandType.Text;
if ( RunCommand(cmd, "select * from MyTable1 where 1 = 1 ") )
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using System.IO;
namespace ConsoleApplication1
{