Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to insert arabic into mysql from asp.net C#

I want to insert arabic content from asp.net page to mysql5.5,I am using mysqlconnector5.2.7 to connect with local mysqlserver.when i tried to insert arabic from asp.net program,null values are inserted into the database,despite of it when i tried to insert from command prompt,all words are showing like ???,I searched more on google,but i could not found any solution.Please see my code below.I altered the database,table and the column of arabic to utf8 using the alter query on command prompt,but still i cannot find any solution,how to display this arabic on datagridview

myconnection.Open();
string insert="insert into home_table(image,content,arabiccontent) values(@image,@content,arabiccontent)";
MySqlCommand cmd = new MySqlCommand(insert,myconnection);
MySqlParameter param = new MySqlParameter("@image", MySqlDbType.VarBinary, image.Length);
param.Value = image;
cmd.Parameters.Add(param);

cmd.Parameters.Add(new MySqlParameter("@content",MySqlDbType.VarChar,Content.Length));

cmd.Parameters["@content"].Value = Content;
cmd.Parameters.Add(new MySqlParameter("@arabiccontent", MySqlDbType.VarChar, contentarabic.Length));
cmd.Parameters["@arabiccontent"].Value = contentarabic.Trim();
cmd.ExecuteNonQuery();
myconnection.Close();

web.config

 <add name="mysqlconnectionstring" connectionString="Data Source=localhost;Database=mydatabase_;Uid=root;Pwd=root;CharSet=cp1256;"/>
like image 701
suhail Avatar asked Dec 10 '25 13:12

suhail


1 Answers

Use this connection string

Datasource=localhost; Database=testdb; Uid=root; Pwd=123;CHARSET=utf8

And make sure it's CHARSET and not CharSet or charset! Also try to change the DEFAULT CHARACTER SET of your tables and fields:

ALTER TABLE `myTbl` DEFAULT CHARACTER SET utf8
like image 62
VahidN Avatar answered Dec 12 '25 01:12

VahidN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!