1

I have this Sql query:

INSERT INTO myTable (myField) VALUES (N'Thermal Oxide: 0 Å to 40 μm')

and I want to exeute it by SqlBulkCopy like that:

DataTable myDataTable=myDb.getData("select top 1* from myTable").Clone();
DataRow dr = myDataTable.NewRow();  
dr["myField"] ="N'Thermal Oxide: 0 Å to 40μm'";
myDataTable.Rows.Add(dr);
this.openCon();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con))   {
    bulkCopy.DestinationTableName = dt.TableName;
    bulkCopy.BulkCopyTimeout = 100;
    bulkCopy.WriteToServer(myDataTable);
}   this.closeCon();

It is work perfect, but my question is: where can I initilize the 'N' prefix? and maybe there is no need?

Thanks, chani

1
  • 2
    There is no need, you are right. Type conversion are handled by the ADO.Net driver. Commented Jul 10, 2012 at 10:58

1 Answer 1

1

Just:

dr["myField"] = "Thermal Oxide: 0 Å to 40μm";

The N'...' is only required for literals in TSQL; but since you are taking data (not TSQL) you do not need to worry about that. In the case of SqlBulkCopy, it will go down to the server in a raw format, not directly as TSQL.

In the more common case of an adapter or ORM, the library will either (most likely) use parameters, or it will worry about the escapting itself.

It perhaps should also be noted that adding 1 row via SqlBulkCopy is overkill. But it should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.