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

What does SqlDbType.Structured mean?

From msdn website I get the following: A special data type for specifying structured data contained in table-valued parameters. It seems my code works with it and without it (pushing table to DB using stored procedure). Can someone explain what…
Zbun
  • 4,875
  • 4
  • 19
  • 28
10
votes
2 answers

poor performance with sqlparameter

I have a web service, so the handler is called multiple times concurrently all the time. Inside I create SqlConnection and SqlCommand. I have to execute about 7 different commands. Different commands require various parameters, so I just add them…
10
votes
3 answers

How to call Stored Procedures (with 2 parameters) in a Stored Procedure?

I have stored procedures with same parameters (server name and date). I want to write a stored procedure and Exec them in that SP (called it SP_All). CREATE PROCEDURE [dbo].[SP_All] AS BEGIN exec sp_1 @myDate datetime, @ServerName sysname exec…
Raha
  • 163
  • 1
  • 2
  • 12
9
votes
6 answers

how to pass sql parameter as null value in integer datatype variable?

how to pass sql parameter as null value in to integer data type variable ? StockBO sBO = new StockBO(); sBO.Mode = 2; if (ddcmpanyname.SelectedIndex != 0) { sBO.Client_id =…
Ayyappan Anbalagan
  • 11,022
  • 17
  • 64
  • 94
8
votes
4 answers

How to mock SqlParameterCollection using Moq

I am trying to mock database operations. I have problem in mocking SqlParameterCollection. I tried to create virtual method that will return DbParameterCollection but then i am loosing all the functionality that SqlParameterCollection gives like…
Asdfg
  • 11,362
  • 24
  • 98
  • 175
8
votes
3 answers

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

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…
fletchsod
  • 3,560
  • 7
  • 39
  • 65
7
votes
3 answers

SqlParameter is already contained by another SqlParameterCollection, but I don't see how

I have the following code. // Get total row count and build Pagination object var countQuery = ArticleServerContext.Database.SqlQuery("GetFullTextSearchCount @SearchTerm", new SqlParameter("@SearchTerm", fullTextQuery)); Pagination…
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
7
votes
1 answer

How to use the SqlParameter.Offset property and ADO.NET to store a binary file in SQL Server 2012

I am currently learning how to store files without using FILESTREAM attribute on varchar(max) in SQL Server, because I dont need to store very large binary files. Despite that I want to store the binary data by small chunks of it. What I found was…
Christian Rizov
  • 331
  • 2
  • 11
5
votes
4 answers

Is there a way to determine if a parameter in a stored proc has a default value (and thus not required) in code - .Net?

I am already pulling the parameters from the stored proc sent in like this: foreach (SqlParameter param in cmd.Parameters) { if ((param.Direction == ParameterDirection.Input) || (param.Direction ==…
Todd Vance
  • 4,627
  • 7
  • 46
  • 66
5
votes
3 answers

Why is the decimal SqlParameter getting mangled?

I'm sending a decimal value to a sproc in the following way: SqlParameter meh = new SqlParameter("Foo", SqlDbType.Decimal); meh.Value = "0.00001"; meh.Precision = ((System.Byte)(12)); meh.Scale = ((System.Byte)(9)); When I profile the database to…
LaserJesus
  • 8,230
  • 7
  • 47
  • 65
5
votes
2 answers

How do I pass a null value into a parameter for a SqlCommand

Before anyone comments that this has been answered before in other question I KNOW that..but in spite of the answers I have reviewed at Assign null to a SqlParameter Sending null parameters to Sql Server Best method of assigning NULL value to…
Bastyon
  • 1,571
  • 4
  • 21
  • 28
5
votes
2 answers

How does SqlParameter know the type

I was wondering how does SqlParameter know the type when it is not specified? For example, when instantiating a parameter object you don't need to specify the DB Type. Somehow when the command is executed .net handles this for you. Behind the…
Dr Schizo
  • 4,045
  • 7
  • 38
  • 77
5
votes
2 answers

Creating a SQL table variable in a stored procedure

I want to create SQL variable table in stored procedure which include this; Select a,b,c,d from **@tablename** where a=1 and c=0 How can do this with sp when creating sp?
user5164496
5
votes
2 answers

Multiple INSERT in one query using MySqlCommand

I am using the following code: string cmd = "INSERT INTO " + Tables.Lux() + " VALUES(NULL, @Position, @Mode, @Timer)"; try { using (var MyConnection = new…
Hamma
  • 183
  • 1
  • 4
  • 12
5
votes
4 answers

Escaping special characters in a SQL LIKE statement using sql parameters

I have a table containing products. I need to make a query finding all the matching results to an user-input value. I am using SqlParameter for the insertion of the inputs. SqlCommand findProcutsByPattern = new SqlCommand( "SELECT *" + "…
zhulien
  • 507
  • 2
  • 8
  • 17
1
2
3
21 22