sqlparameter

Right syntax of SqlParameter

十年热恋 提交于 2019-12-02 06:57:03
问题 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 this one, I'm getting these errors : Error 3 Argument 1: cannot convert from 'System.Data.DbType' to 'object[]' Error 2 The best overloaded method match for 'System.Data.SqlClient.SqlParameter.SqlParameter(object[])' has some invalid arguments Full

Right syntax of SqlParameter

寵の児 提交于 2019-12-02 05:49:57
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 this one, I'm getting these errors : Error 3 Argument 1: cannot convert from 'System.Data.DbType' to 'object[]' Error 2 The best overloaded method match for 'System.Data.SqlClient.SqlParameter.SqlParameter(object[])' has some invalid arguments Full function code : public User GetUser(int id) { var u = new User(); lock (locker) { connection = new

SqlCommand Parameters size confusion

荒凉一梦 提交于 2019-12-01 15:45:02
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? 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 varchar , nvarchar etc. The size is 4 bytes for an int. See DbParameter class on msd n for more info. It is

nVarchar and SqlParameter

我的梦境 提交于 2019-12-01 11:03:15
I'm developing an application which must support several languages. To solve the special characters problem I'm using NVarhcar for my text fields. So my SQL query for a text field is insert into tbl_text(text)values(N'Chci tančit v oblasti') My problem is to put it in SqlCommand, wich is "insert into tbl_text(text)values(N@text)" . It saves "N@text" in the DB table, sure. Do you guys know someway to do it? I'm using C# and SQL 2008. Sorry if it was hard to understand my question. My English is poor =/ Add(string, object) has been deprecated for this reason (from Pablo Castro of the SQL Server

Best method of assigning NULL value to SqlParameter

≡放荡痞女 提交于 2019-12-01 02:36:39
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 kind that will allow me to specify a NULL value in the SqlParameter declaration? public int batchInsert (

What does SqlDbType.Structured mean?

无人久伴 提交于 2019-11-30 19:52:17
From msdn website I get the following: A special data type for specifying structured data contained in table-valued parameters. It seems my code works with it and without it (pushing table to DB using stored procedure). Can someone explain what does it do - I didn't understand it from the definition. SQL Police In SQL Server, you can define stored procedures and you can pass tables as parameter. This is then called a table valued parameter . When you are programming in C#, you can pass such a table-valued parameter to the database by using the SqlDbType.Structured constant. This post shows an

How does SqlCommand sanitize parameters?

折月煮酒 提交于 2019-11-30 18:56:48
Using SqlParameters is a recommended method to prevent SQL Injection in your database queries. Where can I find the code/function that internally sanitizes these parameters? I'd like to re-use this function in a custom implementation of mine. I tried to find it using Reflector, but was unsuccessful. It protects against SQL Injection, not XSS, and there is no code or function that sanitizes the parameter data. The protection is accomplished by transmitting the parameter values to the server separately from the query string, so that the values are never substituted directly into the sql

What does SqlDbType.Structured mean?

帅比萌擦擦* 提交于 2019-11-30 04:21:03
问题 From msdn website I get the following: A special data type for specifying structured data contained in table-valued parameters. It seems my code works with it and without it (pushing table to DB using stored procedure). Can someone explain what does it do - I didn't understand it from the definition. 回答1: In SQL Server, you can define stored procedures and you can pass tables as parameter. This is then called a table valued parameter . When you are programming in C#, you can pass such a table

How does SqlCommand sanitize parameters?

落花浮王杯 提交于 2019-11-30 02:59:08
问题 Using SqlParameters is a recommended method to prevent SQL Injection in your database queries. Where can I find the code/function that internally sanitizes these parameters? I'd like to re-use this function in a custom implementation of mine. I tried to find it using Reflector, but was unsuccessful. 回答1: It protects against SQL Injection, not XSS, and there is no code or function that sanitizes the parameter data. The protection is accomplished by transmitting the parameter values to the

Dynamic where clause in parameter

℡╲_俬逩灬. 提交于 2019-11-28 14:20:21
问题 I am currently trying to build up the where clause of an SqlCommand . something similar to this myCommand.CommandText = "SELECT * " + "FROM TABLE1 " + "@whereClause"; //I build up the where clause with a StringBuilder myCommand.Parameters.AddWithValue("@whereClause" theClause.ToString()); But it doesn't seem like this is possible. I got the exception : SqlException Incorrect syntax near '@whereClause' The reason I want to do something like this is because I want to avoid X call to the