Skip to content

BulkCopy and chinese characters #220

Open

Description

Using BulkCopy to insert Chinese data into the table in batches can be successfully stored in the database,however, the Chinese characters stored in the database are garbled. For example, the string "你好" becomes "浣犲ソ " in the database.
The type of the field is varchar, and according to requirements, nvarchar cannot be used instead.
Please tell me how to solve this requirement, thank you.

stmt, err := txn.Prepare(mssql.CopyIn("t_batch_update", mssql.BulkOptions{}, "id", "name"))
if err != nil {
	fmt.Println(err)
	return
}
for i := 0; i < 10; i++ {
	_, err = stmt.Exec(i, "你好")
	if err != nil {
		fmt.Println(err)
		return
	}
}
result, err := stmt.Exec()
if err != nil {
	fmt.Println(err)
	return
}
err = stmt.Close()
if err != nil {
	fmt.Println(err)
	return
}
err = txn.Commit()
if err != nil {
	fmt.Println(err)
	return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions