Questions tagged [sqlcommand]

Represents a Transact-SQL statement or stored procedure to execute against a SQL Server database which is used in Microsoft .NET.

SqlCommand is a class in the .NET Framework whose instances represent a SQL statement to later be executed against a SQL Server database.

General syntax:

SqlCommand is instantiated with a query string and a connection. In C#:

SqlCommand cmd = new SqlCommand("select CategoryName from Categories", con);

Reference

SqlCommand on MSDN

919 questions
-1
votes
1 answer

Data from database to Label

I would like to get data from my database to my label. This is my code: con = new SqlConnection(conS); try { con.Open(); string q = "SELECT SearchTerm FROM Sentiment WHERE Sentiment = 'positive'"; SqlCommand query = new SqlCommand(q,…
Fairuz
  • 11
  • 3
-1
votes
2 answers

CommandText property has not been initialized error in gridview

I have a gridview and I want to checked line in insert but I see this error: CommandText property has not been initialized. I guess my mistake about strArrays. I'm working two days about it How can I fixed? StringBuilder stringBuilder = new…
mguzel
  • 1
  • 3
-1
votes
1 answer

Delete Duplicate Row sql oledb in vb.net

I am using this sql statement to join two tables together where the return_date in one table is null. SELECT Customers.CustomerID, Customers.First_Name, Customers.Surname, Customers.House_No, Customers.Street, Customers.County,…
-1
votes
1 answer

Not Inserting values in Table

I have written an Stored procedure for inserting values in the table. Please see the SP for your reference:- ALTER PROCEDURE [dbo].[AddingpagesinGrid] (@page_title NVARCHAR(100), @page_description…
Rahul Sutar
  • 260
  • 9
  • 36
-1
votes
1 answer

Using sqlcommand to fill reportviewer but only selected fields get filled in from one table how do i add another table?

I am working on an etime history application, the data is brought into sql from adp application. Requirement User wants to see old time sheet information for a particular employee Process User clicks on 1) paygroup from drop down 2) the employees…
-1
votes
2 answers

C# CSV reader that can handle truncated rows?

Best practice question: I have a CSV file that looks like this: 1,2,3 1,,3 ,2,3 ,,3 1 1 1 I want it to go into SQL: 1,2,3 1,null,3 null,2,3 null,null,3 1,null,null 1,null,null 1,null,null The last three rows are giving me problems.…
user2366153
  • 63
  • 1
  • 8
-1
votes
2 answers

How to easily null certains parts of a SqlCommand?

I am writing a kind of democrazy Programm for my collegues with a SQL Server (Express). Thusfar i got along with it pretty well, but I fail for about an hour not, to create a simple way of using a SqlCommand with parameters, that can be null, but…
ExNought
  • 193
  • 1
  • 11
-1
votes
2 answers

Convert empty string into Null to save Null Values into SQL Server database

I just read out very nice answers to save null into database column using string.IsNullOrWhiteSpace(textbox.tex) ? (object)textbox.text: DBNull.Value; or using cmd.Parameters.AddWithValue("foo", foo == null ? (object)DBNull.Value :…
Wasay
  • 83
  • 2
  • 9
-1
votes
2 answers

Insert into the database "MDF" does not work

Honestly I've tried everything and in many ways, but I can not give a simple INSERT in the database. Please could someone tell me what is wrong with this code? using (SqlConnection con = new SqlConnection(AcessoBD.ConnectionString)) { string…
Ronald Araújo
  • 1,395
  • 4
  • 19
  • 30
-1
votes
1 answer

Use SQL Select command as forumula in a table

I have a SELECT command that I used to pull out a single value from my table. My table (Table_1) is: So for my new table I want to use the command SELECT [AMOUNT] FROM [TABLE_1] WHERE [REDS] = 'Type1' and so on for each of the types in my new…
CSharpDev4Evr
  • 535
  • 1
  • 11
  • 35
-1
votes
1 answer

SqlCommand SUM decimal issue with output

I have got this code which SUM number(9,2) values in SQL DB, but the output is System.Data.SqlClient.SqlCommand. I know I have to Convert it somehow but have no idea how? Would you please suggest me something? Thank you very much for your time. …
Blaze M
  • 200
  • 4
  • 16
-1
votes
1 answer

Very complicated TSQL with INNER JOIN the same table twice

Let's say I have 2 tables (in fact there are more in this command, but only those affect question). Table A have unique Accounts and Table C have Unique Materials. Now lets say Unique Account with ID 11 can have few Unique Materials (ex.: 10, 18,…
Alt
  • 58
  • 7
-1
votes
5 answers

I am using a sql select command to select all records in a table where the date is between two values

This is what I have, but currently it does not work.. Help? sqlGVQuarterly.SelectCommand = "SELECT [CleaningID], [WorkType], [QuarterSection], [BasinID], [RecordDate], [TotalFootage], [H2O], [GritRemoved], [StartingStreet], [LocationPurpose],…
-1
votes
1 answer

c#, how to Reuse the SqlCommand and OleDbCommand

this is the url i refer to: http://support.microsoft.com/kb/317559 i study their method and had applied them, everything is fine until i include 2_2, error msg: No current query in data reader. I already close my drSelect1_1 under 2_1 if statement.…
melvintcs
  • 551
  • 3
  • 13
  • 34
-2
votes
3 answers

C#, trouble with SQLreader/command

I have some trouble with the SqlDataReader: public string GetVareNavn(string streg) { string navn = ""; SqlConnection myCon = DBcon.getInstance().conn(); string query = "SELECT Navn FROM Vare WHERE Stregkode…
Lahno
  • 21
  • 1
  • 1
  • 3