Questions tagged [sqlparameter]

a .NET class for representing SQL parameters in SqlCommands

SqlParameter is a noninheritable .NET class in the System.Data.SqlClient namespace whose instances represent a parameter for a SqlCommand.

319 questions
2
votes
1 answer

SQLParameter of XML type with whitespace elements, loses the whitespace?

I've got a problem with SQLParameter when I try to use one to store into a column of XML type. I am creating the parameter of SqlDbType.Xml. It appears that any XML Elements that are only white space are converted to closed elements. This is the…
Tristan
  • 165
  • 6
2
votes
1 answer

DbParameter IsNullable functionality?

I have not worked with parameters in ADO.Net very much. I'm writing a custom .Net data provider (modeled on SqlClient), and have to implement the IsNullable property in my parameter class, which inherits from DbParameter. My data provider will not…
Darryl
  • 1,531
  • 15
  • 26
1
vote
3 answers

Is there a better way to call a Stored Procedure with SqlParameters in VB?

Anyone know of a better way to create and initialize SqlParameters in VB.NET? Using 3 lines per variable seems quite excessive. Unfortunately the constructors for this class are rather ridiculous, so I'm thinking of just writing my own sub for…
Chiramisu
  • 4,687
  • 7
  • 47
  • 77
1
vote
1 answer

How to know/check whether a value is SqlDbType compatible or not?

I'm assigning objects to this list of SqlParameter and then trying to execute the SqlCommand, but it throws an exception saying that one of the objects could not be converted into SqlDbType. Preferably I want to handle such objects before adding…
MrClan
  • 6,402
  • 8
  • 28
  • 43
1
vote
2 answers

SqlDatasource select parameters

Here is my sql datasource details
bp581
  • 859
  • 1
  • 16
  • 47
1
vote
0 answers

Pass user input (parameters) in the query string (SqlCommand.CommandText), without getting a VS code analysis warning

I think the main point of my question is: what is best practise or is Visual Studio 2019 giving me wrong hints about reviewing the query string? I have checked this example from Microsoft where the warning-code is sent me, but the following warning…
1
vote
0 answers

Is there a benefit to parameterizing SQL WHERE clauses that always have the same value?

This question came up recently and I couldn't find any information on it. lets say I have an SQL query like the following: SELECT * FROM example_table WHERE type=1 The type that I'm selecting will never change. Are there any benefits, for…
Yugspy
  • 35
  • 3
1
vote
1 answer

Execution timeout expiry when executing a stored procedure which uses a table valued parameter

I have a stored procedure which uses a table valued parameter (tvp). In my application, I use a datatable as a SqlParameter to match the tvp structure. The problem is that it sometimes takes 25 seconds just to insert the data (30k rows give or take)…
1
vote
0 answers

ExecuteScalar function fails. Must declare the scalar variable '@DeviceId'

I have a controller that receives a list of objects. First it checks if any of these objects already exists in the table by using ExecuteScalar. If rows already exist, we run the Update stored procedure. If not, we run the Insert stored procedure.…
Gabriel
  • 346
  • 5
  • 24
1
vote
2 answers

Can't solve "Sqlparameter is already contained by another SqlparameterCollection"

I am using 2 threads (from same class) in a windows service. I always getting the same error message: "The SqlParameter is already contained by another SqlParameterCollection. at System.Data.SqlClient.SqlParameterCollection.Validate(Int32 index,…
1
vote
1 answer

Assigning multi value parameter (values) to a local parameter in sql query

I have a situation where I need to store the multi value parameter to a local parameter in sql query. In the SSRS report builder I have created two multi value parameters @Customer and @LogisticsGroup And in my SQL query , I have to assign those…
1
vote
1 answer

How do i determine the SQLDBType of a variable to be added to a parameter?

How do I determine which SQLDBType to assign to a parameter depending on the input variable to store in the DB? Is there a GetType equivelant to test with? If IsNumeric(ParameterValue) Then Parameter.SqlDbType = SqlDbType.Float ElseIf…
Middletone
  • 4,190
  • 12
  • 53
  • 74
1
vote
0 answers

Adding Time Range to a Single Date in a Parameter - SQL Report Builder/SSRS

I'm working on building a couple reports for our company in SSRS in which we are looking to setup a date range between two dates with either a fixed time range set to the single date or to be able to define the time range for the single date. Does…
1
vote
1 answer

Pass a list as a parameter to an oracle query

This code works for a query parameter that is a single value: public void GetById(long id) { var sql = "SELECT * FROM table1 WHERE id = :id"; using(var cmd = new OracleCommand(sql, oracleConnection)) { cmd.Parameters.Add(new…
user2404501
1
vote
2 answers

Generic way of adding SqlParameter to the SqlCommand

We have a legacy C# application where we have a lot of inline SQL queries that are being executed against the input that was passed by the user. So, obviously SQL injection came into the picture. Now we want to fix it but the thing is we want to go…
Silly Volley
  • 463
  • 1
  • 5
  • 15