SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size

How to insert Unicode Text from VB 2008 into Table in Microsoft SQL Server?

E-mail Print PDF
This article describes about how to insert Unicode data into SQL Server 2000.
  • Take not that fields to be stored Unicode data in SQL Server Table must be nvarchar, nchar, or ntext
  • Choose Latin1_General_BIN for Collation property of each Unicode field (see image below)

  • Assume that we have one SQL Server table as below:
    Student (stdid: int, lastname: nvarchar(50), firstname: nvarchar(50))
  • Write Visual Basic .Net 2008 Code as below:
    Dim cn As New OleDb.OleDbConnection
            cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI; " & _
                                    "Data Source=.; " & _
                                    " Persist Security Info=False; Initial Catalog=Test"
            cn.Open()
    
            Dim cmd As New OleDb.OleDbCommand
            cmd.Connection = cn
            cmd.CommandText = "INSERT INTO student(stdid, lastname, firstname) " & _
                            " VALUES(" & Me.txtID.Text & "," & _
                            "N'" & Me.txtLastName.Text & "'," & _
                            "N'" & Me.txtFirstName.Text & "')"
            cmd.ExecuteNonQuery()
    
            cn.Close()