sqlparameters

Is it possible to get the parsed text of a SqlCommand with SqlParameters?

∥☆過路亽.° 提交于 2019-11-28 11:58:27
What I am trying to do is create some arbitrary sql command with parameters, set the values and types of the parameters, and then return the parsed sql command - with parameters included. I will not be directly running this command against a sql database, so no connection should be necessary. So if I ran the example program below, I would hope to see the following text (or something similar): WITH SomeTable (SomeColumn) AS ( SELECT N':)' UNION ALL SELECT N'>:o' UNION ALL SELECT N'^_^' ) SELECT SomeColumn FROM SomeTable And the sample program is: using System; using System.Data; using System

SqlParameter does not allows Table name - other options without sql injection attack?

浪子不回头ぞ 提交于 2019-11-27 05:13:25
I got a runtime error saying "Must declare the table variable "@parmTableName" . Meaning having table name as sql parameter in the sql-statement is not allowed. Is there a better option or suggestion than allowing sql injection attack? I don't want to do this C# script for sql statement " DELETE FROM " + tableName + " " ; using(var dbCommand = dbConnection.CreateCommand()) { sqlAsk = ""; sqlAsk += " DELETE FROM @parmTableName "; sqlAsk += " WHERE ImportedFlag = 'F' "; dbCommand.Parameters.Clear(); dbCommand.Parameters.AddWithValue("@parmTableName", tableName); dbConnection.Open(); rowAffected

How to pass XML from C# to a stored procedure in SQL Server 2008?

♀尐吖头ヾ 提交于 2019-11-27 04:23:20
I want to pass xml document to sql server stored procedure such as this: CREATE PROCEDURE BookDetails_Insert (@xml xml) I want compare some field data with other table data and if it is matching that records has to inserted in to the table. Requirements: How do I pass XML to the stored procedure? I tried this, but it doesn’t work: [Working] command.Parameters.Add( new SqlParameter("@xml", SqlDbType.Xml) { Value = new SqlXml(new XmlTextReader(xmlToSave.InnerXml, XmlNodeType.Document, null)) }); How do I access the XML data within the stored procedure? Edit: [Working] String sql = "BookDetails