After typing in Arabic in the form I press an insert button to insert the fields in the db. But characters turn to strange question marks like :"?????"
. That doesn't happen with numbers or English characters.
How to type Arabic and still have it in the db as Arabic, not as "?????"
?
Here is some code
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["StoreConnectionString"].ToString());
public AddBook()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string X;
cn.Open();
SqlCommand cm = new SqlCommand("SELECT COUNT(*) FROM StoreItem", cn);
Int32 count = (Int32)cm.ExecuteScalar();
X = count.ToString();
cn.Close();
SqlCommand cmd = new SqlCommand("insert into StoreItem (ID, Title, Writer, Price, Qun, Date) Values ('" + X + "','" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + textBox4.Text + "', '" + DateTime.Now.ToString("d/M/yyyy") + "')", cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
textBox1.Text = null;
textBox2.Text = null;
textBox3.Text = null;
textBox4.Text = null;
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
And
private void Rsh()
{
SqlDataAdapter ADAP = new SqlDataAdapter("Select * FROM StoreItem", cn);
DataSet DS = new DataSet();
ADAP.Fill(DS, "Store");
dataGridView1.DataSource = DS.Tables["Store"];
dataGridView1.Columns[1].Width = 200;
dataGridView1.Columns[0].HeaderCell.Value = "#";
dataGridView1.Columns[1].HeaderCell.Value = "عنوان الكتاب";
dataGridView1.Columns[2].HeaderCell.Value = "الكاتب";
dataGridView1.Columns[3].HeaderCell.Value = "السعر";
dataGridView1.Columns[4].HeaderCell.Value = "الكمية";
dataGridView1.Columns[5].HeaderCell.Value = "تاريخ دخول";
}
surly Your datatype for those column is varchar.
You just need to change it to nvarchar and it will be get saved. Also dont forget to add a prefix N. Refer to following query.
if name is nvarchar
insert into Emp (name) values (N'test')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With