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
4
votes
1 answer

VB.Net IIf function in adding SqlParameter

I am rewriting this long INSERT statement and parameters used to look like this: cmd.Parameters.AddWithValue("@Website", General.fnSQLNullValues(tWebsite.Text)) Where General.fnSQLNullValues is this: Public Shared Function…
Scott Selby
  • 9,420
  • 12
  • 57
  • 96
3
votes
2 answers

Issues with SqlParameter constructor vs object initializer

Given the following line of code: cmd.Parameters.Add(new SqlParameter("@displayId", SqlDbType.NVarChar).Value = customer.DisplayID); I receive the following error: The SqlParameterCollection only accepts non-null SqlParameter type objects, not…
Pete Maroun
  • 2,045
  • 2
  • 18
  • 27
3
votes
3 answers

Incorrect syntax for SELECT TOP with a Parameter

I used to have this one Dt = MyMod.GetDataTable("SELECT TOP " & QuestionsPerCats(i) & " * From Questions WHERE CategoriesID ='" & Cats(i) & "' ORDER BY NEWID()") but now i decided to use sqlparameters like Dim cmd As New SqlCommand("SELECT TOP…
OrElse
  • 9,709
  • 39
  • 140
  • 253
3
votes
2 answers

Why does IS NULL work but SQL Parameter with DBNull.Value for DateTime does not?

I have a C# console application that is performing a database lookup on SQL Server 2014. It queries against a table with a DateTime column called EffectiveDate which allows nulls. If I write a standard SQL query that uses 'WHERE EffectiveDate IS…
sldorman
  • 145
  • 2
  • 11
3
votes
2 answers

Is it possible to create an XmlReader from output SqlParameter of type SqlDbType.Xml?

This is my parameter definition: var param = new SqlParameter { ParameterName = "@param", SqlDbType = SqlDbType.Xml, Direction = ParameterDirection.Output, Size = int.MaxValue }; command.Parameters.Add(param); Then I…
Schultz9999
  • 8,717
  • 8
  • 48
  • 87
3
votes
3 answers

How to use Parameter List of integers for Oracle with Dapper?

I am trying to re-write some code to use Dapper so I can easily use parameters. I am trying to execute an UPDATE statement on an Oracle database. A list of IDs to UPDATE is passed in as List as parameter. I want to update a field for each of…
jollyroger23
  • 665
  • 1
  • 6
  • 19
3
votes
1 answer

Is there a way to specify the column length in a temp table through the use of a SQL parameter in SQL Server?

Imagine the following temp table is being created in SQL Server: CREATE TABLE #SomeTable ( SomeColumn varchar(50) ) Now imagine there is some VB.NET code creating this table and is also specifying the length of SomeColumn dynamically, in order…
Panzercrisis
  • 4,590
  • 6
  • 46
  • 85
3
votes
1 answer

How can I loop through a table within a stored procedure?

This question evolved from this one. I have two tables that I need to query and glean some calculated sums from; I need a result set based on units -- one row for each Unit, with calculated data for them folded into that row. The two tables contain…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
3
votes
4 answers

Passing multiple SqlParameter to method

In my main form, I have implemented this code.. void SampleMethod(string name, string lastName, string database) { SqlParameter sqlParam = new SqlParameter(); sqlParam.ParameterName = "@name"; sqlParam.Value = name; …
Syntax Error
  • 105
  • 1
  • 4
  • 12
3
votes
1 answer

SqlParameter Exception: The SqlParameter is already contained by another SqlParameterCollection

I am getting an exception The SqlParameter is already contained by another SqlParameterCollection I have moved my SqlParameter calls out of the foreach loop as I thought that was the issue but I am still getting the same exception. private void…
Jon H
  • 273
  • 2
  • 5
  • 14
3
votes
1 answer

C# Select in SQL Server just using the Date with sql parameters

I am currently trying to do a Select in my SQL Server database using a parameter with Datetime type. But I need this parameter only has the format YYYY-MM-DD date because of the following query in SQL I'm using and it's working : select …
3
votes
1 answer

Is it correct to use -1 as a size for an output SqlParameter to retrieve a VARBINARY(max) value?

I have a stored procedure with an OUTPUT parameter of the varbinary(MAX) type: ALTER PROCEDURE [dbo].[StoredProcedure1] ... @FileData varbinary(MAX) OUTPUT AS ... I don't know what would be the actual size of the returned data, so I can't use…
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
3
votes
2 answers

SQL Server : drop table with SQL parameters

I'm trying to drop a table using SqlParameters. I have this code . dbCon.Open(); DataRowView d= (DataRowView) cmbTabele.Items[cmbTabele.SelectedIndex]; string name = (d["table_name"]as string); SqlCommand com=new SqlCommand("drop table @nume ",…
user3052078
  • 487
  • 1
  • 8
  • 20
3
votes
2 answers

What size for a SqlDbType parameter with bigint?

What is the size to specify for a bigint parameter? SqlParameter param = new SqlParameter("@Param", SqlDbType.Bigint); param.Size = ??? Or can specifying the size be omitted altogether?
reformed
  • 4,505
  • 11
  • 62
  • 88
3
votes
1 answer

How does the SqlCommand handle parameters with integer types?

If I have this variable: int value = 4; which is to be passed as some sql parameter: SqlCommand sqlcmd = new SqlCommand(); sqlcmd.Parameters.Add(new SqlParameter("@value", value)); Will it be converted to string and handled automatically? or could…
user2405469
  • 1,953
  • 2
  • 22
  • 43