我如何使用手柄Verbatim String Literals?

时间:2013-08-12 03:42:36

标签: c# string oracle string-literals verbatim

我在oracleCommand下面,并且喜欢在下面更改但是有错误...除了我的+ item +和+ txtSrcUserID.Text.ToUpper()+之外没有。在oracleCommand中。如何将它们添加到我的命令中?

原始

foreach (string Items in listBox39.Items)
                    {
                        using (OracleCommand crtCommand = new OracleCommand(@"SELECT  REGEXP_REPLACE ( REPLACE ( dbms_metadata.get_ddl ('PROCEDURE', 'HELL_'), '""USER1"".'),'^\s+', NULL, 1, 0, 'm') FROM dual", conn1))
                        {

                        }
                    }

我喜欢与下面的内容类似

foreach (string Items in listBox39.Items)
                        {
                            using (OracleCommand crtCommand = new OracleCommand(@"SELECT  REGEXP_REPLACE ( REPLACE ( dbms_metadata.get_ddl ('PROCEDURE', '+ Items +'), '"" + txtSrcUserID.Text.ToUpper() + "".'),'^\s+', NULL, 1, 0, 'm') FROM dual", conn1))
                            {

                            }
                        }

1 个答案:

答案 0 :(得分:0)

foreach (string Items in listBox39.Items)
{
    using (OracleCommand crtCommand = new OracleCommand(@"SELECT  REGEXP_REPLACE ( REPLACE ( dbms_metadata.get_ddl ('PROCEDURE', '" + Items + @"'), '""" + txtSrcUserID.Text.ToUpper() + @""".'),'^\s+', NULL, 1, 0, 'm') FROM dual", conn1))
    {

    }
}

但正如@SLaks在评论中建议的那样,最好使用参数:

OracleCommand.Parameters

OracleCommand SQL Parameters Binding