sqlparameter

SqlCommand Parameters size confusion

[亡魂溺海] 提交于 2019-12-19 12:25:43
问题 I have the following line of code: sqlcommand.Parameters.Add("@LinkID", SqlDbType.Int, 4).Value = linkID; But, I'm slightly confused about the use of size . Is this saying that its 4 bytes in size? Or a length of 4 so 1234 is acceptable but 12345 is too big? 回答1: For the types with fixes size you should omit this argument, simply: sqlcommand.Parameters.Add("@LinkID", SqlDbType.Int).Value = linkID; The size argument is only relevant for parameters with a type that can have variable size like

SqlCommand Parameters size confusion

扶醉桌前 提交于 2019-12-19 12:25:38
问题 I have the following line of code: sqlcommand.Parameters.Add("@LinkID", SqlDbType.Int, 4).Value = linkID; But, I'm slightly confused about the use of size . Is this saying that its 4 bytes in size? Or a length of 4 so 1234 is acceptable but 12345 is too big? 回答1: For the types with fixes size you should omit this argument, simply: sqlcommand.Parameters.Add("@LinkID", SqlDbType.Int).Value = linkID; The size argument is only relevant for parameters with a type that can have variable size like

Best method of assigning NULL value to SqlParameter

不羁的心 提交于 2019-12-19 05:11:12
问题 I have a number of optional input parameters I am using in a C# class method. Since the optional syntax creates a value of '0' when the parameter is not used, the SQL insert command I call in the method winds up inserting as such. However, I need the command to insert a NULL value instead of a 0 when the parameter is not being used. What is the best way to accomplish this without using a large amount of 'if' statements? Below is the code I am referring to. Is there syntax/a command of some

How to create NVarchar(max) Sqlparameter in C#? [duplicate]

余生颓废 提交于 2019-12-17 16:45:08
问题 This question already has answers here : What size do you use for varchar(MAX) in your parameter declaration? (5 answers) Closed 5 years ago . I've got the following code to pull back a DataTable using a stored procedure and inputting a string parameter @JobNumbers, which is dynamically created string of job numbers (and therefore length is unknown): using (SqlConnection connection = new SqlConnection(con)) { SqlCommand cmd = new SqlCommand("dbo.Mystoredprocedure", connection); cmd

SqlParameter and ExecuteNonQuery causing unrepeatable time outs

╄→гoц情女王★ 提交于 2019-12-12 05:08:35
问题 I recently inherited some code that is having occasional time-out issues. I am mostly familiar with ORM's, so I am having trouble determining if anything is wrong in this code. When it does not time out, it works in a couple of seconds. Time-outs take about a minute. Here is the code: Dim sql As String = "UPDATE VendorInfo SET " & _ "AbsInkUpdateStatus=@AbsInkUpdateStatus, AccountingNotes=@AccountingNotes, " & _ "AccountNumber=@AccountNumber, Address_Ship=@Address_Ship, " & _ "Address0=

Failed to convert parameter value from a DateTime to a Byte[]

被刻印的时光 ゝ 提交于 2019-12-12 02:47:55
问题 I'm getting error converting parameters from DateTime to Byte[]. The idea is to show data between 2 specified dates that are entered via controls and displayed on GridView, and using a stored procedure to access data. I don't understand the error, but I'm guessing that all the data is put in an Array and passed on to stored procedure: string sDateBegin = Request.Form["fromDate"]; DateTime dtDateBegin = Convert.ToDateTime(sDateBegin); SqlParameter prmDateBegin = new SqlParameter("datebegin",

Create Data.SqlClient.SqlParameter with a SqlDataType, Size AND Value inline?

╄→гoц情女王★ 提交于 2019-12-11 20:29:36
问题 I have a function which can take a number of SqlParameter objects: Public Shared Function RunSQL(sqlInput As String, Optional params As Data.SqlClient.SqlParameter() = Nothing) As String The aim is basically being able to call the function and create the parameters if needed, as needed. Unfortunately, there do not appear to be any constructors available that will allow me to specify the Value as well as the SqlDbType without having to add lots of additional parameters (that I do not need) as

Pass same parameters multiple times in SQLitecommand

╄→尐↘猪︶ㄣ 提交于 2019-12-11 19:19:32
问题 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 p.location_id = l.location_id and p.poi_id = ? union all select lon, lat from xtdp_poi_address pa, xtdp_location l where pa.location_id=l.location_id and pa.poi_id= ? As you can see it's required 3 times same parameter and it's value parameter ("?") ::: value (ex. 12345) I have written below

Having multiple values assigned to a single ADO.Net SqlClient parameter

那年仲夏 提交于 2019-12-11 18:31:55
问题 I wish to run an SQL select statement similar to this SELECT * FROM CatalogueItems WHERE id IN (1,10,15,20); using ADO.Net SqlClient style @name parameters. I've tried using a stored SQL strings SELECT * FROM CatalogueItems WHERE id IN (@Ids) and then in my C# code SqliteCommand command; //... //returns 0 results command.Parameters.Add("@Ids", null).Value = "1,10,15,20"; //returns 0 results command.Parameters.Add("@Ids", DbType.String).Value = "1,10,15,20"; //returns 1 or more results command

Save large binary data into sql DB with C#

浪子不回头ぞ 提交于 2019-12-11 18:28:40
问题 I need a code to store (eventually large) files into DB using C#. The solution I'm using is sth like: (I'm using varbinary(MAX) column in the DB) 1) Create SqlCommand 2) Create SqlParameter 3) Set parameter.Value = File.ReadAllBytes(filePath) 4) Execute SqlCommand Is there any more effective solution? Since the file can be large, I'm affraid of performance problems, when reading all bytes into memory, and then storing them into DB. Thank you in advance 回答1: What you have is the best you can