ASP.NET 使用FastMember 把List转成 DataTable

FastMember 可以在 Nuget 里找到

配合 Dapper 很好用。

用 Dapper 的时候,要定义实体,像这样调用conn.Query<OrderModel>(sql).ToList(), 不然 FastMember 转成的 DataTable 是空的

private void btnSearch_Click(object sender, EventArgs e)
{
	using (var conn = Db.OpenConnection())
	{
		var sql = "SELECT * FROM dbo.[Order] where 客户名称 like '%张%'";
		var data = conn.Query<OrderModel>(sql).ToList();

		DataTable table = new DataTable();
		using (var reader = ObjectReader.Create(data))
		{
			table.Load(reader);
			this.dataGridView1.DataSource = table;
		}
		
	}
}

VC获取进程加载的DLL模块

VC++获取进程加载的DLL模块:

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <psapi.h>

// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS// and compile with -DPSAPI_VERSION=1

int PrintModules(DWORD processID)
{
    HMODULE hMods[1024];
    HANDLE hProcess;
    DWORD cbNeeded;
    unsigned int i;

    // Print the process identifier.

    printf("\nProcess ID: %u\n", processID);

    // Get a handle to the process.

    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
                               PROCESS_VM_READ,
                           FALSE, processID);
    if (NULL == hProcess)
        return 1;

    // Get a list of all the modules in this process.

    if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
    {
        for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
        {
            TCHAR szModName[MAX_PATH];

            // Get the full path to the module's file.

            if (GetModuleFileNameEx(hProcess, hMods[i], szModName,
                                    sizeof(szModName) / sizeof(TCHAR)))
            {
                // Print the module name and handle value.

                _tprintf(TEXT("\t%s (0x%08X)\n"), szModName, hMods[i]);
            }
        }
    }

    // Release the handle to the process.

    CloseHandle(hProcess);

    return 0;
}

int main(void)
{

    DWORD aProcesses[1024];
    DWORD cbNeeded;
    DWORD cProcesses;
    unsigned int i;

    // Get the list of process identifiers.

    if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
        return 1;

    // Calculate how many process identifiers were returned.

    cProcesses = cbNeeded / sizeof(DWORD);

    // Print the names of the modules for each process.

    for (i = 0; i < cProcesses; i++)
    {
        PrintModules(aProcesses[i]);
    }

    return 0;
}

VC++开机启动

VC++写的程序,想要开机启动,可以使用注册表来实现,代码如下:

inline void SetAutoRun()
{
       TCHAR szFilePath[MAX_PATH];
       memset(szFilePath, 0, MAX_PATH);
       if (GetModuleFileName(NULL, szFilePath, MAX_PATH))
       {
              HKEY hKey;
              CString strRegPath = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
              if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, strRegPath, 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
              {
                     RegSetValueEx(hKey, _T("SecContrl"), 0, REG_SZ, (LPBYTE)szFilePath, (lstrlen(szFilePath) + 1)*sizeof(TCHAR));
              }
              RegCloseKey(hKey);
       }
}
inline void ReSetAutoRun()
{
       HKEY hKey;
       CString strRegPath = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, strRegPath, 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
       {
              RegDeleteValue(hKey, _T("SecContrl"));
       }
       RegCloseKey(hKey);
}

windows批处理执行Mysql脚本

windows批处理执行Mysql脚本,批处理脚本代码如下:

@echo off

%cd%\mysql\bin\mysql.exe -u root -h 127.0.0.1 -p123456 -e"use cqms;select 1;select 2;"

echo 数据库升级完成
pause

通过文件执行

@echo off

%cd%\mysql\bin\mysql.exe -u root -h 127.0.0.1 -p123456 < c:\test\aaa.txt

echo 数据库升级完成
pause