Operate the mysql database in the .NET environment - continued

xiaoxiao2021-03-06  51

From: http://www.cnblogs.com/jimmy/archive/2004/09/15/43402.aspx

Operate the mysql database in the .NET environment - continued

Finish

Operate the mysql database in the .NET environment

"When communicating with friends, I found Bytefx.Data why I couldn't display Chinese reasons and the way to solve (thanks to Venscent). The original Bytefx.data defaults to rely on the mysql default character set (Latin1) to encode, so display When Chinese is garbled. You can change the default character set of mysql: Add a line of default-character-set = GB2312 in "My.ini", as shown below: Of course, if you installed MySQL installed in other OS, you can Use the corresponding instructions to set this property. The result is OK pull .... Everyone can use this free Winter Winter pulling using this free Winter Winter pulling use Bytefx.data or some code of MySQL's official connector / net is as follows:

Using

System.windows.forms;

Using

System.data;

Using

Mysql.data.mysqlclient; mysqlconnection2.connectionstring

=

"

Connection timeout = 30; server = 192.168.8.112; user ID = zjmzs; password = zjmzs; port = 3306; data = popoface; pooling = true; min pool size = 3; Max pool size = 101

"

MysqlConnection2.open (); MySQLDataAdapter Adapter

=

New

MysqldataAdapter (); adapter.selectCommand

=

New

MySQLCommand

"

Select * from UploadCFD

"

, Mysqlconnection2; adapter.fill (dataset1);

In addition, in the http://www.cybercom.net/~zbrad/dotnet/mysql/ this place looked at his MySQL solution. Brad Merrill The people working in Microsoft mainly wrote a DLL calling mysql's libmysql.dll's interface, which is not a good method, but this has to be a function of the function in Libmysql.dll. In the mysql.cs provided by Brad Merrill, some commonly used functions have been written, but I don't try it in actually. If you are interested, you can try it. Let's take a look at the code of mysql.cs. :

Using

System;

Using

System.security;

Using

System.Runtime.InteropServices;

/ ** /

///

Connects to a mysql server /// value on success, else returns intptr.zero

[SuppressunmanagedCodeSecurity] [DLLIMPORT

"

Libmysql.dll

"

Charset =

System.Runtime.InteropServices.charset.ansi, entrypoint

=

"

MySQL_REAL_CONNECT

"

, EXACTSPELING

=

True

)]]

public

Static

Extern

INTPTR Connect (INTPTR DB, [In]

String

Host, [in]

String

User, [in]

String

Passwd, [in]

String

DBNAME,

Uint

Port, [in]

String

Socketname,

Uint

Flags);

/ ** /

///

SELECTS A DATABASE /// Zero for success. Non-Zero if An error Occurred.

[SuppressunmanagedCodeSecurity] [DLLIMPORT

"

Libmysql.dll

"

Charset

=

System.Runtime.InteropServices.charset.ansi, entrypoint

=

"

MySQL_SELECT_DB

"

, EXACTSPELING

=

True

)]]

public

Static

Extern

int

SelectDB (INTPTR conn, [in]

String

DB);

/ ** /

///

Closes a Server connection

[SuppressunmanagedCodeSecurity] [DLLIMPORT

"

Libmysql.dll

"

, EntryPoint

=

"

MySQL_Close

"

, EXACTSPELING

=

True

)]]

public

Static

Extern

Void

Close (INTPTR DB);

/ ** /

///

Executes a SQL Query Specified as a string /// Number of rows change, -1 if zero

[SuppressunmanagedCodeSecurity] [DLLIMPORT

"

Libmysql.dll

"

Charset

=

System.Runtime.InteropServices.charset.ansi, entrypoint

=

"

MySQL_QUERY

"

, EXACTSPELING

=

True

)]]

public

Static

Extern

int

Query (INTPTR conn, [in]

String

Query);

/ ** /

///

Retrieves a complete result set to the client /// An IntPtr result structure with the results. IntPtr.Zero if an error occurred. [SuppressUnmanagedCodeSecurity] [DllImport (

"

Libmysql.dll

"

, EntryPoint

=

"

MySQL_STORE_RESULT

"

, EXACTSPELING

=

True

)]]

public

Static

Extern

INTPTR Storeresult (INTPTR CONN);

/ ** /

/// Returns the number of rows in a result set

[SuppressunmanagedCodeSecurity] [DLLIMPORT

"

Libmysql.dll

"

, EntryPoint

=

"

MySQL_NUM_ROWS

"

, EXACTSPELING

=

True

)]]

public

Static

Extern

int

Numrows (INTPTR R);

/ ** /

/// Returns the number of columns in a result set

[SuppressunmanagedCodeSecurity] [DLLIMPORT

"

Libmysql.dll

"

, EntryPoint

=

"

MySQL_NUM_FIELDS

"

, EXACTSPELING

=

True

)]]

public

Static

Extern

int

Numfields (INTPTR R);

转载请注明原文地址:https://www.9cbs.com/read-116639.html

New Post(0)