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

.NET SqlParameter constructor inconsistent?

Can anyone tell me what is going on in this function?? In the following code snippet, user.Id = 0, id.Value = 0 and id.SqlDbType = Int.. as expected since user.Id is an int field. However, error.Value = null and error.SqlDbType = BigInt. What gives?…
Cailen
  • 690
  • 1
  • 9
  • 23
1
vote
1 answer

Right syntax of SqlParameter

I'm trying to convert : command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = id }); To a normal SqlParameter : command.Parameters.Add(new SqlParameter(DbType.Int32) { Value = id }); I've managed to convert every line now besides…
Random
  • 431
  • 8
  • 20
1
vote
3 answers

Difference between DbNull.Value and DbNull.Value.ToString()

I wanted to learn which usage is true? if(!string.IsNullOrEmpty(parentID)) cmd.Parameters.Add(new SqlParameter("@ParentSesID", parentID)); else cmd.Parameters.Add(new SqlParameter("@ParentSesID",…
cihadakt
  • 3,054
  • 11
  • 37
  • 59
1
vote
1 answer

How to insert sql parameter inside a text query

I'm trying to pass a parameter to a sql query (in c#) but the parameter is inside a text block: SqlCommand cmd = new SqlCommand(@"EXEC sp_helptext N'dbo.@spname';"); cmd.Parameters.AddWithValue("@spname", "StoredProcedureName"); If I use the stored…
mmarques
  • 625
  • 3
  • 9
  • 27
1
vote
1 answer

Conversion failed when converting date and/or time from character string #2

Here's my code: DateTime Dob = Convert.ToDateTime("1/1/1800"); DateTime Dod = Convert.ToDateTime("1/1/1800"); if (!string.IsNullOrEmpty(p.birthday)) Dob = Convert.ToDateTime(p.birthday); if (!string.IsNullOrEmpty(p.deathday)) Dod =…
Mike Marks
  • 10,017
  • 17
  • 69
  • 128
1
vote
1 answer

Ado.net command.Paramaters.AddWithValue for update statement?

model public class Users { public int Id { get; set; } public string UserName { get; set; } public string DisplayName { get; set; } public string Password { get; set; } public string Email { get; set; } public DateTime?…
AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197
1
vote
0 answers

SqlDataAdapter.Fill times out when using a Parameter

We currently have a very simple query that returns the last row of a table for a given account. SELECT TOP 1 * FROM tbl WHERE AccountID = @AccountID ORDER BY tblID DESC; When filling a DataTable from a DataAdapter with this query using the…
Trevor Watson
  • 415
  • 1
  • 8
  • 20
1
vote
7 answers

Must declare the scalar variable “@Login”. Error when trying to add parameter to SqlDataSource

I have this error : Must declare the scalar variable "@Login". My code : using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["intranetv2"].ConnectionString)) { SqlCommand cmd = new SqlCommand("insert into…
Portekoi
  • 1,087
  • 2
  • 22
  • 44
1
vote
3 answers

Syntax Error on a Sql Parametrized update command - c#

It's my first SQL Parametrized update command in c# and i have a syntax error when i exectued my update. Here is my code : string maRequete = "UPDATE " + strNomTable + " set " + "evetype = @evetype ," + "evedes = @evedes ," +…
Walter Fabio Simoni
  • 5,671
  • 15
  • 55
  • 80
1
vote
1 answer

add list of sqlparameters to sqldatasource update

Im having trouble trying to create and set some sqlupdate parameters, my code below will hopefully be self explaniatory. vis studio is not happy with my PArams being in the datasource at the mo Thanks for any advice chaps protected void…
AlexW
  • 2,843
  • 12
  • 74
  • 156
1
vote
4 answers

How to insert multiple records into database with SqlParameter in C#

I am trying to run the following code: using (SqlConnection conn = new SqlConnection(connstr)) { conn.Open(); StringBuilder sqlStr = new StringBuilder("INSERT into Customers values ( @name, @address, @city, @state)"); SqlCommand cmd =…
girlcode
  • 3,155
  • 5
  • 27
  • 41
1
vote
1 answer

DB2 Parameter binding for literal comparisons

I've got SQL for DB2 of the following abbreviated format: Select ... From ... Where ... ((COL1 IS NULL) And ('' = ?)) ... Order By ... The rough purpose of this SQL is to return Null records if the input against COL1 is blank. However, if I try to…
1
vote
3 answers

Is there any way to reduce this ado.net code?

I need reduce significantly this code, is there any way to create a sql parameter describing its direction? Here is the code: Dim Oparam1 As SqlParameter = New SqlParameter("@ROJO", SqlDbType.Int) Dim Oparam2 As SqlParameter = New…
Diego Pacheco
  • 193
  • 2
  • 2
  • 10
1
vote
1 answer

Stored Procedures, ExecuteScalar and Parametes

I have a stored procedure that I call like this: string proc = "SpCreate '00111', 3"; using (SqlCommand command = new SqlCommand(proc, conn)) { command.CommandType = CommandType.Text; command.CommandTimeout = 1000; string…
cdub
  • 24,555
  • 57
  • 174
  • 303
1
vote
2 answers

Pass a SQL condition as a OleDb parameter

I have following code: Dim executedCmd As OleDb.OleDbCommand = m_dbMgr.GetCommand() executedCmd.CommandText = "select * from [Parameters] where " Dim SQLcondition As String = String.Empty For i As Integer = 0 To ParameterName.Count - 1 …