sqlparameter

The SqlParameter is already contained by another SqlParameterCollection

﹥>﹥吖頭↗ 提交于 2019-12-25 07:35:48
问题 I'm using EF DbContext SqlQuery to get a list of paged objects using PagedList (https://github.com/TroyGoode/PagedList) and I'm getting the following error: "The SqlParameter is already contained by another SqlParameterCollection" Here's my repository code: var db = (DbContext)DataContext; const string sqlString = @" WITH UserFollowerList AS ( SELECT uf.FollowId FROM UserFollow uf WHERE uf.UserId = @UserId ) SELECT * FROM UserFollowerList uf INNER JOIN [User] u ON uf.FollowId = u.UserId WHERE

how to late parameter bind to dynamic sql statement in a stored procedure

天大地大妈咪最大 提交于 2019-12-25 03:15:48
问题 I am attempting to dynamically build a T-SQL statement based on a FieldMapping table and some business rules. Cut the long story short, I have a function that will return the SQL statement as a varchar(max) that I will execute as EXEC (@Sql) in my stored procedure. Allow me to demonstrate with a test table create procedure [dbo].[sp_TestInsert] ( @Id int, @Name varchar(20), @Surname varchar(20), @Age int, @Source varchar(1) ) as declare @sql varchar(max) -- Return SQL statement that depends

Why my ADO.NET queries does not run in single execution but they will run in seperate executions?

拟墨画扇 提交于 2019-12-25 01:12:10
问题 Regarding a question and its related answer, I'm trying to create a new table type using SQL queries and run a join query on data which are of this table type. I put both queries in the same script, i.e. create type and select but it is not working. My query is as below (the whole code is brought in the end of question): IF TYPE_ID(N'BranchMappingType') IS NULL CREATE TYPE BranchMappingType As Table (COL_ServerID int, COL_ServerSchema Common._SMALL_, COL_TableName Common._SMALL_, COL_BranchNo

Syntax Error on a Sql Parametrized update command - c#

倖福魔咒の 提交于 2019-12-24 16:22:49
问题 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 ," + "evecli = @evecli ," + "eveusermo = @eveusermo ," + "eveinterv = @eveinterv where eveNum = " + '"' + strEvtNumeroString.ToString() + '"'; OleDbCommand DbCommand = new OleDbCommand(maRequete); DbCommand.Parameters.Add("@evetype", OleDbType.VarChar); DbCommand.Parameters

No SqlParameter.UdtTypeName on netcoreapp1.1! How to use UDT?

白昼怎懂夜的黑 提交于 2019-12-23 12:33:58
问题 This UdtTypeName property is required to read or write Geography, Geometry or HierarchyId. I can't find any workaround or post/information on this subject. Does anyone have an explanation? 回答1: This is not implementend in netcoreapp1.1. There is an issue about that in the dotnet corefx project, referencing all the missing API of System.Data.SqlClient, and especially about UdtTypeName: https://github.com/dotnet/corefx/issues/17126 来源: https://stackoverflow.com/questions/44315760/no

SQL Parameters Inside A Loop

牧云@^-^@ 提交于 2019-12-23 05:24:00
问题 i have a list that i am pulling things out of to insert into a database. This is not going to be a web app so i have just been doing as follows: string sqlStorage = (null,"asd"), for (int i = 1; i < listsize; ) { sqlStorage = sqlStorage + "(null,someVariableFromLoop)"; i++ } string connString = "Server=localhost;..........."; MySqlConnection conn = new MySqlConnection(connString); MySqlCommand command = conn.CreateCommand(); command.CommandText = @"INSERT INTO table1 VALUES " + tempSQLStorage

how to pass sql parameter as null value in integer datatype variable?

我的未来我决定 提交于 2019-12-21 09:30:11
问题 how to pass sql parameter as null value in to integer data type variable ? StockBO sBO = new StockBO(); sBO.Mode = 2; if (ddcmpanyname.SelectedIndex != 0) { sBO.Client_id = Convert.ToInt16(ddcmpanyname.SelectedValue); } else { sBO.Client_id = Convert.ToInt16(DBNull.Value);//Object cannot be cast from DBNull to other types. sBO.Client_id =DBNull.Value;//Cannot implicitly convert type } ds=_StockController.StockGet(sBO); i changed the code like this it gives error like i my comment check else

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

别说谁变了你拦得住时间么 提交于 2019-12-20 06:33:56
问题 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 (misleading, at any rate), because there is no more data with the failing set than with the successful set, and so it shouldn't take any longer to run the "bad" data than the good. Mor enlightening, perhaps, are the other err msgs that appear after

How can I loop through a table within a stored procedure?

江枫思渺然 提交于 2019-12-20 02:32:16
问题 This question evolved from this one. I have two tables that I need to query and glean some calculated sums from; I need a result set based on units -- one row for each Unit, with calculated data for them folded into that row. The two tables contain the following pertinent members: CustomerCategoryLog : Unit varchar(25) MemberNo varchar(10) Category varchar(50) Subcategory varchar(50) BeginDate Datetime EndDate Datetime ReportingMonthlySales : Unit (VarChar) MemberNo (VarChar) MonthlySales

Is there a way to determine if a parameter in a stored proc has a default value (and thus not required) in code - .Net?

馋奶兔 提交于 2019-12-19 19:51:56
问题 I am already pulling the parameters from the stored proc sent in like this: foreach (SqlParameter param in cmd.Parameters) { if ((param.Direction == ParameterDirection.Input) || (param.Direction == ParameterDirection.InputOutput)) { jsonReturn += "{\"paramName\":\"" + param.ParameterName + "\", \"paramType\":\"" + param.SqlDbType.ToString() + "\"},"; } } I looked into the SqlParameter object and could not find a way to see if it could tell me whether the Parameter had a default value...