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
2 answers

C# - Output SqlParameter uses different values then the ones given?

I have a SqlCommand which runs a stored procedure that contains two integer output parameters. Right before the SqlCommand runs I can see that the output parameters are set to the correct values, however when the command actually executes, it uses a…
Rachel
  • 130,264
  • 66
  • 304
  • 490
2
votes
1 answer

NullReferenceException when Adding a SqlParameter to a SqlParameterCollection

I have been wracking my brain for hours trying to solve this so hopefully someone here can help me work this out. I am inserting into a database in a c# application. Being a good coder, I am parameterizing my query. The relevant code is: int…
James Sunderland
  • 135
  • 1
  • 1
  • 13
2
votes
1 answer

SqlParameter - Setting to DEFAULT Value

How do I set a SqlParameter's value to the equivalent of a SQL INSERT statement's DEFAULT keyword? MSDN documentation says to "use null or do not set Value to use the default value for the parameter." However, doing either results in a SqlException…
Ben Gribaudo
  • 5,057
  • 1
  • 40
  • 75
2
votes
1 answer

Receiving an error when attempting to update a record

In my program I have a function titled runSQL, here it is: Dim Connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=TrainingLog.accdb") Dim DT As New DataTable Dim DataAdapter As OleDb.OleDbDataAdapter …
DatBrummie
  • 63
  • 1
  • 4
  • 10
2
votes
1 answer

How could I infer parameters & returned columns from a SQL query string?

I'm building an application that allows users to input SQL query strings. These query strings will contain 0 or more parameters and 1 or more returned columns. Is there a standard approach to parsing SQL queries to extract these elements? Ideally,…
Tom Wright
  • 11,278
  • 15
  • 74
  • 148
2
votes
3 answers

adding sqlparameter without name

I'm trying to create a sub to add as many parameters as I want, I used to do this in vb6 but here in vb.net it requires me to provide the parameter name (.add(@parameter, value)). I need to find a way to do it without knowing the parameter name, i…
Kevin
  • 21
  • 3
2
votes
0 answers

How to send multiple value with sql parameter for in()

I guess it is simple but I couldn't figure it out. I want it for asp.net project. Normally I use Int for sql parameter for one int value but I need it for in() statement. alter procedure abc @id int select * from tbl where id = @id It works for…
2
votes
2 answers

Why SqlParameter always set parameter is null?

using (SqlCommand cmd = new SqlCommand()) { DataTable dt = new DataTable(); cmd.CommandText = p; cmd.CommandType = CommandType.Text; SqlConnection con = new SqlConnection("--"); cmd.Connection = con; cmd.Connection.Open(); …
mtaha
  • 71
  • 5
2
votes
1 answer

InsertCommand.Parameters.Add size parameter for datetime

I need to know what the size parameter should be for a DateTime value using the following syntax: adapter.InsertCommand.Parameters.Add("@deliveryDateAndTime", SqlDbType.DateTime,10,"deliveryDateAndTime"); I cannot use the following syntax because…
sagesky36
  • 4,542
  • 19
  • 82
  • 130
2
votes
2 answers

Difference between the both parameter assignment

actually I have a doubt, so please clear it. I have 2 line do the same work, see below 1. cmd.Parameters.AddWithValue("@UserName",objBELUserDetails.UserName); 2. cmd.Parameters.Add("@UserName",SqlDbType.Nvarchar,50). …
Gaurav
  • 557
  • 4
  • 11
  • 28
2
votes
1 answer

Implicit Operators and Assignments to SqlParameter.Value with IConvertible Error

I have a class member type as Int32 but the requirement is that the .ToString() method of this member needs to return a special formatted version of the Int32. So I created a struct with implicit operators which preserves the simple value assignment…
2
votes
2 answers

SQL Parameters with Like Terms in .Net

I have a pretty complex query and was fixing my like terms (which I have as a separate db table and load them into my search query), but when I parameterize it, my query gives different results. So the old query had a like section like so: ((v.title…
cdub
  • 24,555
  • 57
  • 174
  • 303
2
votes
2 answers

Adding SQL Parameters in C#

What is the difference between: myCommand.Parameters.AddWithValue("search", "% " + myValue + " %"); and: myCommand.Parameters.AddWithValue("@search", "% " + myValue + " %"); The difference above is with and without the @ symbol. Does it do…
cdub
  • 24,555
  • 57
  • 174
  • 303
2
votes
2 answers

Difference between SqlParameter.Add and AddWithValue

Possible Duplicate: Difference between Parameters.Add and Parameters.AddWithValue From MSDN code, what is the difference between these two: SqlCommand command = new SqlCommand(commandText, connection); //#1 …
cdub
  • 24,555
  • 57
  • 174
  • 303
2
votes
1 answer

Ado.net and Sp's Parameters in cache?

Im reading the code for Microsoft.ApplicationBlocks.Data ( code is here ) But I've notice something strange : in one of the function ( executeNonQuery) he tries to read Sp's param from cache and if not exists , he put them into the cache ( not…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792