Hay, I tried to get the Urdu Fonts from MySql Database using C# in Visual Studio 2010 in Windows Forms Application. When I get the value from table into my variable it shows the characters in ???? symbols. wherein PHP it is working very good without any problem.
But in PHP i have used the following code:
Now I do not know how to insert this line of code to my query in C#:
I am using the following code in my C# class:
and I am getting the following error message:
class System.String
Represents text as a series of Unicode characters.
Error:
Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
Please help me in this regards. Thanks in advance.
Shah Hussain
But in PHP i have used the following code:
Code:
<?php
class CRUD {
var $con;
//function to make connection to database
function connect(){
$this->con = mysql_connect("localhost","root","password") or die(mysql_error());
[B]mysql_query("SET character_set_results=utf8", $this->con);
mb_language('uni');
mb_internal_encoding('UTF-8');
mysql_select_db("database1",$this->con);
mysql_query("set names 'utf8'",$this->con);[/B]
}
//function to get the field value from the table specified in the query
function getValue($sql,$value){
$this->connect();
$result = mysql_query($sql,$this->con);
if(mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result);
$value = $row[$value];
}
else {
$value = "";
}
return $value;
}
?>
Code:
mysql_query("SET character_set_results=utf8", $this->con);
mb_language('uni');
mb_internal_encoding('UTF-8');
mysql_select_db("database1",$this->con);
mysql_query("set names 'utf8'",$this->con);
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data.Odbc;
using System.Data;
using System.Windows.Forms;
namespace Madrasa_Mgt.classes
{
class CRUD
{
private static string userid;
private static string userkey;
private OdbcConnection con;
private OdbcDataReader odr;
private OdbcCommand cmd;
public bool flag;
UTF8Encoding utf8 = new UTF8Encoding();
public CRUD() {
//connectToDb();
setVars();
}
private OdbcConnection connectToDb(){
try {
con = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; uid=root; password=thefire; Server=localhost; Option=16834; Database=madrasa_jamia");
if (con.State == ConnectionState.Closed) {
con.Open();
}
}
catch (Exception exc) {
this.msgErrorEx(exc);
}
return con;
}
private void setVars() {
try {
this.connectToDb();
string sql = "SELECT mad_name,mad_addr,phone,banner_photo,owner_name,licence_number,purchase_date,vendor_name,vendor_addr,vendor_phone,is_ok FROM configuration";
cmd = new OdbcCommand(sql, this.con);
cmd.ExecuteNonQuery();
odr = cmd.ExecuteReader();
if (odr.Read())
{
GlobalVars.MadName = odr["mad_name"];
GlobalVars.MadrasaAddress = odr["mad_addr"];
GlobalVars.Phone = odr["phone"];
GlobalVars.Banner = odr["banner_photo"];
GlobalVars.OwnerName = odr["owner_name"];
GlobalVars.LicenseNumber = odr["licence_number"];
GlobalVars.PurchasedDate = odr["purchase_date"];
GlobalVars.VendorName = odr["vendor_name"];
GlobalVars.VendorAddress = odr["vendor_addr"];
GlobalVars.VendorPhone = odr["vendor_phone"];
GlobalVars.IsOk = odr["is_ok"];
}
}
catch (Exception exc) {
}
}
class System.String
Represents text as a series of Unicode characters.
Error:
Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
Please help me in this regards. Thanks in advance.
Shah Hussain
Comment