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
3
votes
3 answers

why we use "@" while inserting or updating or deleting data in sql table

I just want to know why we use "@" while inserting or updating or deleting data in sql table, as I used @name like below. cmd.Parameters.Add(new SqlParameter("@fname", txtfname.Text));
Gaurav
  • 557
  • 4
  • 11
  • 28
3
votes
2 answers

The parameterized query is truncated and parameters are lost

I have a piece of code: command.Parameters.Clear(); command.Parameters.Add(ownerUserIDParam); command.Parameters.Add(buddyUserIDParam); command.Parameters.Add(timestampParam); command.Parameters.Add(new SqlParameter("@GiftID",…
2
votes
1 answer

Stored procedure parameter with XML query in MSSQL gives "argument must be string literal"

I'm trying to query a table with a column which is xml data with the query and value functions. When using regular string literals it's all okay, but if I put that in a stored procedure and try to use variables it doesn't work. I suppose I'm not…
Patrick
  • 17,669
  • 6
  • 70
  • 85
2
votes
4 answers

C# SqlParameter - provide SQL (Microsoft SQL)

I am currently tasked with a project on a database whose schema cannot be changed. I need to insert a new row into a table that requires an ID to be unique, but the original creators of the structure did not set this value to autoincrement. To go…
will
  • 1,397
  • 5
  • 23
  • 44
2
votes
1 answer

What is the syntax for initializing a SQLParameter array in VB.Net from what I have in C#

It has been way to long since I have been involved in VB so I need some help here. I have the following in my C# code SqlParameter[] param = new SqlParameter[0]; ...some code... param = new SqlParameter[2]; param[0] =…
mattgcon
  • 4,768
  • 19
  • 69
  • 117
2
votes
2 answers

ASP.NET What reference am I missing for Parameter Direction and SQLDBType

Hey just wondering what references I need to add to my VS2008 Project to get the following working Name ParameterDirection is not declared. Name SqlDbType is not declared Thanks
StevieB
  • 6,263
  • 38
  • 108
  • 193
2
votes
1 answer

How to convert SqlCommand query to use parameters built using concatenated strings including variables using ternary operators

this is my first question, hopefully I do things correctly. Also to preface, I'm a programming noob tasked with developing and fixing some code where I work since the programmer we've had until now left. And if done quite well for now with my…
2
votes
0 answers

Change parameter indicator in SqlCommand from '@' to ':'

I'm working on library which allows me to create connections, commands, readers etc for 3 db types: oracle, postgresql and sql server. I need to pass parameters into query but it seems like postgres and oracle supports : sign as parameter indicator,…
Adam Mrozek
  • 1,410
  • 4
  • 26
  • 49
2
votes
2 answers

SqlParameter "disappears" when assigned a value of null?

I stumbled across the following issue recently: Assigning a null to the Value property of an SqlParameter appears to cause the parameter to be omitted from the query rather than passing NULL. This results in a potentially misleading error message…
Sigurd Garshol
  • 1,376
  • 3
  • 15
  • 36
2
votes
5 answers

nVarchar and SqlParameter

I'm developing an application which must support several languages. To solve the special characters problem I'm using NVarhcar for my text fields. So my SQL query for a text field is insert into tbl_text(text)values(N'Chci tančit v oblasti') My…
André
  • 21
  • 1
  • 1
  • 2
2
votes
1 answer

How to secure my query: I get The SqlParameter is already contained by another SqlParameterCollection

I'm trying to parameterize all queries to satisfy SQL Injection findings from the PUMA vulnerability scanning extension in Visual Studio. While doing that, I'm running into the error in the title: The SqlParameter is already contained by another…
cheluto2
  • 35
  • 6
2
votes
1 answer

Dealing with potentially null datetime value in a SQLParameter

I am trying to do what I thought was a pretty straightforward thing, but am having issue. I have code in a .NET application to insert a new record into a table using SQLCommand. I am passing in what could either be a datetime value or it could be…
DeveryDay
  • 161
  • 15
2
votes
0 answers

SQL Query Param type affects query speed

We had a slow page loading and upon investigating it was the query execution. I noticed the page on the dev server was fine and I noticed when I ran the query via MSSQL Mgt Studio it ran fine, only on the CF page it was slow. I noticed the ids were…
Leeish
  • 5,203
  • 2
  • 17
  • 45
2
votes
3 answers

Getting error message in SqlDataAdapter.Update()

I have a DB table (which is empty in this example) create table words ( id int not null, word nvarchar(50) not null ) and a DataGridView which I'm filling like that: private SqlConnection _conn; private SqlDataAdapter…
cesarito
  • 136
  • 2
  • 5
2
votes
2 answers

How can I use SQL Parameters in a CONTAINS clause?

I am looking to do something like: select * from MyValues where CONTAINS(MyValues.Value, ' @p0 OR @p1 OR @p2 or @p3 ') I issue the query through EF's SqlQuery() method like: query = context.Database.SqlQuery(@"select * from MyValues …
Dan
  • 894
  • 9
  • 21