小编Muk*_*Ran的帖子

如何在SQL-Update语句中处理 - 转义单引号和双引号

我有这个示例T-SQL查询并在SQL-Server-2008上尝试此操作.

DECLARE nvarchar(1000) @wstring = "I asked my son's teacher, "How is my son doing now?"" 

UPDATE tablename SET columnname = ' " & @wstring & " ' where ... blah ... blah
Run Code Online (Sandbox Code Playgroud)

我知道上面的查询会抛出错误.

那么我如何处理 - 在SQL-Update语句中转义单引号和双引号.

请不要建议在每个报价之前手动添加"斜杠"或单引号,以及bouble-quote.

这是不切实际的,因为上面的示例只是一个sAmple,实际应用程序值超过1000个字符,这将从其他系统源接收.

sql-server-2008 sql-update

22
推荐指数
2
解决办法
11万
查看次数

用于将XML文件读入DataTable的代码

我编写了下面的代码片段,它读取给定的xml文件并将内容写入数据表.请不要建议使用LinqToXml,因为这是一个遗留应用程序.

            // create the DataTable that will hold the data
            DataTable table = new DataTable("ListOfPersonsWithInfo");


            // open the file using a Stream
            using (Stream stream = new FileStream(fileNameWithAbsolutePath, FileMode.Open, FileAccess.Read))
            {
                // create the table with the appropriate column names
                table.Columns.Add("Name", typeof(String));
                table.Columns.Add("ImagePath", typeof(String));
                table.Columns.Add("Address", typeof(String));

                // use ReadXml to read the XML stream
                table.ReadXml(stream);

                // tried with this overload-option as well but didnt help
                //table.ReadXml(fileNameWithAbsolutePath);

                // return the results
                return table;
            }
Run Code Online (Sandbox Code Playgroud)

但是返回的表包含ZERO行...... !!! 其中实际的xml文件有'3行',结构如下(任何IDEA这里出了什么问题?):

<?xml version="1.0" encoding="utf-8"?>
<Details> …
Run Code Online (Sandbox Code Playgroud)

c# xml datatable

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

datatable ×1

sql-server-2008 ×1

sql-update ×1

xml ×1