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

How can I defensively code against randomly referencing "Table 0" and null values?

I am retrieving a moderate amount of data and processing it - nothing unique there. What was odd at first was that with some sets of data, it worked fine, and with others, I got the following err msg: This err msg seems to be total hogwash, though…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
0
votes
1 answer

Converting int to boolean ADO.NET SqlParameter

I am trying to use a stored procedure that returns an int. Then I need to convert int to a boolean (success). SqlParameter Return = new SqlParameter(); Return.ParameterName = "@return"; Return.SqlDbType = SqlDbType.Int; Return.Direction =…
Roux
  • 1
  • 1
0
votes
0 answers

How can I validate that a value passed to a SqlParameter will not fail precision and Scale?

How can I validate that a value passed to a SqlParameter will not fail the Precision and Scale properties at the time of setting the value, rather than waiting for the "System.ArgumentException" to be thrown when ExecuteReader is called on my…
Dib
  • 2,001
  • 2
  • 29
  • 45
0
votes
1 answer

Why this SqlParameterCollection call is throwing error?

This is code sample to call a stored procedure. Second process throws InvalidCastException at runtime. I am trying to add a new SqlParameter into the SqlParametersCollection. I have seen lots of example using the same syntax. using (SqlCommand db =…
DevelopZen
  • 375
  • 4
  • 6
0
votes
1 answer

Getting first N rows between 2 timestamps for each ID Mysql

I have table like below, start_t is my timestamp in unixtime for example (1438326239412) but for simplicity I wrote small numbers here: user_id | start_t | duration 1 12 1 1 15 2 1 4 5 2 …
Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63
0
votes
0 answers

SQL Parameter throwing exception

I have a function in vb.net module that is meant to get the number of records in an access database. Function CalculateRecords(ByVal column As String, ByVal table As String) Dim count As Integer = 0 Using connect As New…
belaythat
  • 45
  • 8
0
votes
1 answer

How to get the Query String variable in ASP.NET and pass it as an Sql parameter?

string userid = Request.QueryString[0].ToString(); string Qid = Request.QueryString[1].ToString(); string connection = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString.ToString(); SqlConnection con = new…
0
votes
1 answer

Configuring SqlParameter as Default-able

I'm leaving my SqlParameter's SqlValue unset to indicate that the parameter should be set to the default value. This is per MSDN documentation: Use null or do not set SqlValue to use the default value for the parameter. When I try to execute the…
Ben Gribaudo
  • 5,057
  • 1
  • 40
  • 75
0
votes
1 answer

Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Data.SqlClient.SqlParameter'

For the code: sqlParameter = parameterSettings.GetParameters(table, config); I'm receiving the error: Error 1 Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Data.SqlClient.SqlParameter' …
jcameron47
  • 65
  • 11
0
votes
0 answers

Escaping SQL in C#/sqlite or: how can I use parameters here?

I realize that handcrafting SQL statements is evil. I also realize that the spontaneous answer of everyone seeing this post will be "Use parameters". I have found several occurences of similar questions around here, but I can't find out how they…
baeuchle
  • 5
  • 2
0
votes
1 answer

c# Is this a safe way for a login form?

myConnection.Open(); myString = textBox2.Text; myPass = textBox1.Text; MessageBox.Show("Connection established!", "Succes!", MessageBoxButtons.OK); using (MySqlCommand looking = new…
0
votes
4 answers

Use of commercial @AT when dealing with data access in ASP.Net?

Two small issues, mostly concerning the @AT syntax when dealing with data in ASP.Net (C#). Most online tutorials show a lot of this following type of code but fail to mention (or I may have overlooked) the actual purpose of the ampersand although…
wilbomc
  • 183
  • 3
  • 13
0
votes
1 answer

ProgrammingError: ('The SQL contains 1 parameter markers, but 2 parameters were supplied', 'HY000')

When running the below script it ends in the following error, as I do find other posts on this error I am not finding the fix similar to my script. Thanks for the help! *Traceback (most recent call last): File "D:\DVO\Bo\Marketing…
Tim
  • 73
  • 2
  • 7
0
votes
1 answer

Query Parameter Value Is Null When Enum Item 0 is Cast with Int32

When I use the first item in a zero-based Enum cast to Int32 as a query parameter, the parameter value is null. I've worked around it by simply setting the first item to a value of 1, but I was wondering though what's really going on here? This one…
Timothy
  • 4,630
  • 8
  • 40
  • 68
0
votes
3 answers

SQLParameter incorrect syntax

I have 2 spots where I need to use SQLParameter to parse SQL. One works and one does not and I cannot figure out why the second one doesn't work. The first one that works is the following: SqlCommand getShopDbNameCommand = new SqlCommand("SELECT…
Giardino
  • 1,367
  • 3
  • 10
  • 30