sqlcommand

Convert SqlCommand Output to List<MyType>?

て烟熏妆下的殇ゞ 提交于 2019-12-01 10:57:07
I am using an ADO.NET SqlCommand with a single SqlDbType.Structured parameter to send a table-valued parameter to a sproc. The sproc returns many rows, which I need to get into a strongly-Typed List of . What is the best way to convert the result set (whether DataTable from a DataAdapter or DataReader bits) into List? Thanks. You can use LINQ with a DataReader: var list = reader.Cast<IDataRecord>() .Select(dr => new YourType { Name = dr.GetString(0), ... }) .ToList(); The most efficient way is using datareader: var items = new LinkedList<MyClass>(); using(var connection = GetConnection()) {

SqlDataReader and SqlCommand

 ̄綄美尐妖づ 提交于 2019-12-01 09:42:11
问题 I have the following code. using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { connection.Open(); SqlCommand select = new SqlCommand("SELECT RTRIM(LTRIM(PART_NO)) AS PART_NO, record FROM [RMAData].[dbo].[IMPORTING_ORDER_EDI] WHERE sessionID = '" + Session.SessionID + "'", connection); SqlDataReader reader = select.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { if (!currentPart.IsActive) { // this

expects parameter '@ID', which was not supplied?

旧城冷巷雨未停 提交于 2019-12-01 02:22:54
I am sending ID as outparameter but its giving error System.Data.SqlClient.SqlException: Procedure or function 'usp_ClientHistoryItem' expects parameter '@ID', which was not supplied. Code using (SqlCommand cmd = new SqlCommand("dbo.usp_ClientHistoryItem", conn)) { SqlParameter parameterID = new SqlParameter("@ID", oReservation.Id); parameterID.Direction = ParameterDirection.Output; cmd.Parameters.Add(parameterID); cmd.Parameters.Add(new SqlParameter("@PhoneNo", oReservation.ClientPhone)); cmd.Parameters.Add(new SqlParameter("@UserId", oReservation.UserID)); cmd.Parameters.Add(new SqlParameter

expects parameter '@ID', which was not supplied?

混江龙づ霸主 提交于 2019-11-30 21:57:16
问题 I am sending ID as outparameter but its giving error System.Data.SqlClient.SqlException: Procedure or function 'usp_ClientHistoryItem' expects parameter '@ID', which was not supplied. Code using (SqlCommand cmd = new SqlCommand("dbo.usp_ClientHistoryItem", conn)) { SqlParameter parameterID = new SqlParameter("@ID", oReservation.Id); parameterID.Direction = ParameterDirection.Output; cmd.Parameters.Add(parameterID); cmd.Parameters.Add(new SqlParameter("@PhoneNo", oReservation.ClientPhone));

Should I migrate to Entity Framework? [closed]

拈花ヽ惹草 提交于 2019-11-30 20:46:24
I've been using the SqlCommand class and writing my own T-SQL queries for a very long time. I've stuck with it because I'm comfortable with it, and it probably stemmed from me starting as a windows developer in the days before we had many other great options. I've been doing web development now for about 10 years, and still using it and writing my own query strings. I've written a dynamic class for all my database needs on the fly, all I have to do is write the T-SQL, which I can do quickly and use in any project. Other developers have got big eyed when they see my code, and encourage me to

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

SqlCommand object, what length of time for CommandTimeout?

醉酒当歌 提交于 2019-11-30 17:06:43
How do I decide what length of time to use as a timeout when using an SqlCommand object? On parts of the code I'm working on (written by somebody else) I have: cmd.CommandTimeout = 60; Which I think is quite short. However, I have seen some people in forums talking about setting it to 30000, which seems too long. How do I know what is best for my application? It seems that people are confused as to whether this is seconds or milliseconds. The documentation states that the timeout is in seconds. A 1-minute timeout seems reasonable for most queries. An 8+ hour timeout doesn't seem reasonable. Do

How to clear mysql screen console in windows?

偶尔善良 提交于 2019-11-30 07:51:23
The title is my question. I googled and try something like mysql> !\ clear mysql> !\ cls mysql> system cls mysql> system clear blah blah ... but none of them works. anyone show me how to clear screen, just like cls command in window This is not possible on Windows. There is an open bug for this issue: Bug #58680: Windows Clear Screen Command EDIT: I don't think Any of the commands will work. In linux Ctrl-L will do the job. in windows there is no equivalent. You can only Exit MySql, Type CLS and then re-enter MySql. Milind Morey mysql> root@xion:~# mysql -uroot -ppassword; Welcome to the MySQL

Using SqlCommand , how to add multiple parameters to its object , insertion via winform in sql table

大憨熊 提交于 2019-11-30 05:32:57
I have ten textboxes in my winform, and i need to save the text typed in these textboxes into 10 columns of a sql database table. so, for this shall i write : INSERT INTO item (c1,c2,c3...,c10) values (@a,@b....@j) cmd.Parameters.Add("@a",SqlDbType.Varchar) cmd.Parameteres["@a"].Value=textbox1.Text; cmd.Parameters.Add("@b",SqlDbType.Varchar) cmd.Parameteres["@b"].Value=textbox2.Text;. . . . . cmd.Parameters.Add("@j",SqlDbType.Varchar) cmd.Parameteres["@j"].Value=textbox10.Text; OR ten separate queries for each textbox: INSERT INTO item (c1) values (@a) cmd.Parameters.Add("@a",SqlDbType.Varchar

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