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

How to use SQL parameters

I'm trying to create a database for a simple game I'm making and having an issue with querying it for the players stats. So far the database can be searched and updated, but only by modifying the actual code can the search terms be changed. The…
Sean Hubbard
  • 37
  • 1
  • 7
1
vote
1 answer

Output SqlParameter Error: the Size property has an invalid size of 0

I know there are a few other threads/questions about this error, but I wanted to get a bit more insight if possible. We've seen this error occur intermittently for a particular piece of code where we have an Integer type output parameter. This is…
Dustin Kofoed
  • 539
  • 1
  • 8
  • 17
1
vote
1 answer

.net dbnull.value sqlparameter where

I have a probleme with a sql query : I would like do something like : SELECT * FROM myTable WHERE [myBoolField] IS NULL if i run this query, i have my results, but i would like use parameters, so i add : SELECT * FROM myTable WHERE [myBitField] IS…
Testman
  • 57
  • 7
1
vote
2 answers

How to pass a datetime parameter from Entity Framework SqlQuery and SqlParameter to a Stored Procedure?

This is my code on server: model.Grid.DataSource = db.Database.SqlQuery("[dbo].[SP_RptCardexSummary_English_1] @OwnerCode, @TypeCode, @MeasurementUnitCode, @FDate", new SqlParameter { ParameterName = "@OwnerCode", Value…
Braveheart6M6
  • 81
  • 3
  • 8
1
vote
1 answer

Different (incorrect) result when executing the same query from c#

I am trying to do some complex manipulations in SQL Server. To prevent any performance penalty, I am trying to do all the manipulations on database side. Below is my query in C# "DECLARE @t AS TABLE (StartTime DATETIME, EndTime DateTime, Value REAL,…
shashwat
  • 7,851
  • 9
  • 57
  • 90
1
vote
1 answer

SQL Where logic parameterized where

I'm attempting to create a parameterized where statement using COALESCE in SQL 2008, and I have the example of: Select * From Receipts Where Receipts.FunctionCode = COALESCE(@FunCode, Receipts.FunctionCode) in hope that if i pass in NULL in…
Terramune
  • 31
  • 6
1
vote
2 answers

String was not recognized when i use datetime.parseexact()

When ever i tries to enter date into sqlparameter it keeps on popping string was not recognized , i even tried to use ParseExact() but its still showing an error. My .aspx :
Akhil R J
  • 184
  • 2
  • 14
1
vote
1 answer

Check if SqlParameter value is in range of it's target SQL column

tldnr; How should I check the bounds on my SqlParameter values before attempting to put them in the database? Longer version: So, I have these dynamically generated SQL statements where I pass in a bunch of SqlParameters. The way we declare…
user420667
  • 6,552
  • 15
  • 51
  • 83
1
vote
1 answer

Incorrect syntax near @para and must declare the table variable @para SQL c#

I load my INFORMATION_SCHEMA.TABLES into a listbox. I let the user select table, then in the listbox next to it the columns for this table appear. I simply get the talbe name like this: tableName = lbTables.GetItemText(lbTables.SelectedItem); now…
CularBytes
  • 9,924
  • 8
  • 76
  • 101
1
vote
1 answer

Pass WHERE/clause to WCF service

I have method on WCF service that accepts four parameters. Method will handle update statement for updating data in MS SQL database. The issue I ran into is that I can't find a way to send clause as parameter. The thing is that WCF can't accept…
SuperManSL
  • 1,306
  • 2
  • 12
  • 17
1
vote
2 answers

Best practice for dynamically building variable length IN SQL clause in C#

Recently I found myself in C#, doing some SQL. This is not exactly my area of expertise. I wrote some code that looks pretty ugly, and am failing to find a better solution anyplace. Many of the answers here on SO pose SQL injection risks, and are…
Mark W
  • 2,791
  • 1
  • 21
  • 44
1
vote
0 answers

Minimum data required to send a valid SqlParameter

I have noticed a strange behavior while building parameters for a stored procedure I call. Within a table used there's a column that has the type VARCHAR(16). When I build the parameter for this column my first instinct was to do it like this: ret =…
Denis Kralj
  • 633
  • 2
  • 12
  • 27
1
vote
2 answers

Insert into temp table from exec call stored procedure

I have a stored procedure where I insert a table into a temporary table and then I read that temp table row by row using a cursor: USE [TEST_DB] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE…
1
vote
1 answer

Pass same parameters multiple times in SQLitecommand

I like to run below query : select lon, lat from rdf_city_poi p, rdf_location l where p.location_id = l.location_id and p.poi_id = ? union all select lon, lat from rdf_poi_address p, rdf_location l where…
Hardik
  • 259
  • 1
  • 2
  • 17
1
vote
2 answers

How to insert value into a table and also update a value in another table using one button?

I have two tables called payment and appointment with relationship with each other using appointmentid. For my current codes, it only insert value into payment table. What I would like to achieve is that if I key in values in the form including the…
Pony
  • 401
  • 3
  • 13
  • 43