如何将波斯语单词插入 SQL Server 数据库?

1 c# character persian

我只是想知道如何将波斯字符插入到我的基于服务的数据库中?

当我保存我的数据时,它显示类似'???'.

我已经检查过这样的问题。但是,这些解决方案没有用。

    private void button1_Click(object sender, EventArgs e)
    {            
            objConnection.Open();

            if (ctypeCheckBox.Checked == true)                
                st = 1;          
            else if (ctypeCheckBox.Checked == false)                
                st = 0;

            string query = "INSERT INTO LectureTable(Cname, Cid, Ccredit, Csession, Ctype, CstartDate, CendDate, CstartTime, CendTime) VALUES('" + cnameTextBox.Text + "','" + cidTextBox.Text + "','" + ccreditTextBox.Text + "','" + csessionTextBox.Text + "','" + st + "', '" + cstartDateDateTimePicker.MinDate + "', '" + cendDateDateTimePicker.MaxDate + "', '" + cStartTimeBox.Text + "', '" + cEndTimeBox.Text + "')";
            SqlDataAdapter SDA = new SqlDataAdapter(query, objConnection);
            SDA.SelectCommand.ExecuteNonQuery();
            MessageBox.Show("Inserted!");

            objConnection.Close();
    }
Run Code Online (Sandbox Code Playgroud)

Yur*_*uri 5

两件事情:

  1. 永远不要将您的查询字符串与值结合使用

    "INSERT INTO LectureTable(Cname, Cid, Ccredit, Csession, Ctype, CstartDate, CendDate, CstartTime, CendTime) VALUES('" + cnameTextBox.Text + "','" + cidTextBox.Text + "','" + ccreditTextBox.Text + "','" + csessionTextBox.Text + "','" + st + "', '" + cstartDateDateTimePicker.MinDate + "', '" + cendDateDateTimePicker.MaxDate + "', '" + cStartTimeBox.Text + "', '" + cEndTimeBox.Text + "')";
    
    Run Code Online (Sandbox Code Playgroud)

    应立即更换

    "INSERT INTO LectureTable(Cname, Cid, Ccredit, Csession, Ctype, CstartDate, CendDate, CstartTime, CendTime) 
    VALUES(@cname, @cid, @ccredit, @csession, @st, @cstartDateDate, @cendDate, @cStartTime, @cEndTimeB)";
    
    Run Code Online (Sandbox Code Playgroud)

然后你应该使用

SDA.SelectCommand.Parameters.AddWithValue("cname",cnameTextBox.Text);
Run Code Online (Sandbox Code Playgroud)

对于所有参数。这将使您免于包括 SQL 注入在内的许多问题。

  1. 在数据库中,您的列应该具有nvarchar数据类型。

祝你好运