Click here to Skip to main content
15,885,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i use this code to update my data bout i get ?????? in the database when i write arabic litter what should i do for that

SQL
create procedure [dbo].[Updateproject]
@ProjectID int,
@Title nchar(10) ,
@Description text ,
@DueBy datetime ,
@Status nvarchar(50)
as
update dbo.uni_project set Status=@Status,Title=@Title,Description=@Description,DueBy=@DueBy where projectID = @ProjectID
return 0
GO


i i use this code in my form

C#
string str = ConfigurationManager.ConnectionStrings["my"].ConnectionString;
                using (SqlConnection sqlcon = new SqlConnection(str))
                {
                    using (SqlCommand cmd = new SqlCommand("Createproject", sqlcon))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("Title", txtTitle.Text);
                        cmd.Parameters.AddWithValue("Description", txtData.Text);
                        cmd.Parameters.AddWithValue("DueBy", cbDate.Text);
                        cmd.Parameters.AddWithValue("username", txtusername.Text);
                        
                        sqlcon.Open();
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("reminder set for" + cbDate.Text);
                    }
                }


What I have tried:

SQL
update dbo.uni_project set Status=@Status,Title=N+@Title,Description=N+@Description,DueBy=@DueBy where projectID = @ProjectID

bout i didn't work
Posted
Updated 12-Feb-19 22:29pm
v2
Comments
Richard MacCutchan 13-Feb-19 4:15am    
It is more likely that you are using the wrong codepage and font when you display the data.
Richard Deeming 14-Feb-19 10:45am    
NB: The text, ntext, and image types have been deprecated for over a decade. They will be removed from a future version of SQL server. You should use varchar(max), nvarchar(max), and varbinary(max) instead.

ntext, text, and image (Transact-SQL) - SQL Server | Microsoft Docs[^]

1 solution

As Richard already mentioned you're probably using the wrong codepage if the problem is within the description field.
Best solution for that is to use ntext instead of text.

If the problem is within the Title or Status fields, then the solution is to never use AddWithValue. Use cmd.Parameters.Add() and specify the type properly.
Read this: Can we stop using AddWithValue() already?[^]
 
Share this answer
 
Comments
Richard Deeming 14-Feb-19 10:46am    
Except ntext has been deprecated for over a decade now! :)

ntext, text, and image (Transact-SQL) - SQL Server | Microsoft Docs[^]
Jörgen Andersson 15-Feb-19 1:58am    
Quite right you are.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900