Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

10 May 2008

Uploading Chinese Text to MySQL database

In SQL Server, if you want to insert Chinese or other language character to a table, it was pretty simple, just specify the column type as NVARCHAR, and when you insert you can just use "N'chinese text here" but I found out that there's no such thing as NVARCHAR in MySQL database and hence this article.

To insert Chinese character:

  • Specify database character-set as UTF-8

  • Specify table or column collation set as UTF-8

  • In your web.config connection string, specify charset UTF-8
    e.g. <add name="MySqlConnString" connectionstring="server=IPAddress;userid=mysqluser;password=pa$$w0rd;database=mydb;pooling=false;charset=utf8 "/>

    This is to tell the application to use UTF-8 charset when talking to the database

02 March 2008

Connecting to MySQL Database from ASP.Net - Overview

I didn't think it was possible before. I thought only PHP can connect to MySql database. I was so wrong! The steps to connect to MySql database from ASP.Net 2.0 page is pretty simple (I didn't think so previously though), so let me share my experience here then.

There are a few steps to do this:

  1. Install MySql database
    You can install the Community version if you're not feeling rich.
  2. Install PhpMyAdmin or SqlYog or other softwares that can be used to administer MySql database
    I prefer SqlYog that PhpMyAdmin as it's simpler and easier to use, but still let me create my database, tables, columns, run my queries, etc. But if you're requirements are more complex, then maybe you'll need PhpMyAdmin.
  3. Install ASP.Net Mysql Connector
  4. Sometimes even after you install the connector, you still need to add the mysql.dll file to your bin directory (ASP.Net 1.1) or add reference in ASP.Net 2.0
  5. Write your code!