Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BulkCopy and chinese characters #220

Open
Flashcqxg opened this issue Sep 17, 2024 · 0 comments
Open

BulkCopy and chinese characters #220

Flashcqxg opened this issue Sep 17, 2024 · 0 comments

Comments

@Flashcqxg
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant