sqlcommand

When would SqlCommand.ExecuteReader() return null?

When using calling the SqlCommand.ExecuteReader() method, ReSharper tells me I have a possible NullReference exception when I use the SqlDataReader object afterwards. So with the following code: using (SqlConnection connection = GetConnection()) { using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandText = ;...

Do I have to Close() a SQLConnection before it gets disposed?

Per my other question here about Disposable objects, should we call Close() before the end of a using block? using (SqlConnection connection = new SqlConnection()) using (SqlCommand command = new SqlCommand()) { command.CommandText = "INSERT INTO YourMom (Amount) VALUES (1)"; command.CommandType = System.Data.CommandType.Text; ...

sql command for reading a particular sheet, column ...

Dear All ... This is probably a very stupid question for SQL stalwarts, but I just want one SQL command. Details, I am using a data analysis tool called R, this tool uses ODBC to read data from XLS. I am now trying to read data from an XLS file. The ODBC tool in R accepts SQL commands. Question, Can someone give me an SQL command th...

Why am I getting a sqlcommand timeout in the application?

I am getting sqlcommand timeout issues when I debug the application even though the stored procedure runs in less than 25 seconds in management studio. I set the timeout attribute to 180 seconds and still get the error. Any suggestions? ...

How to add a number to a Sqlcommand.Parameters?

Here's my method: public void EjecutarGuardar(string ProcedimientoAlmacenado, object[] Parametros) { SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); SqlCommand Command = Connection.CreateCommand(); Command.CommandText ...

In what situations is the prepare method of a SqlCommand object useful?

Does any body know that in what situations the prepare method of an ADO.NET SqlCommand Object is useful? ...

SqlCommand object - set it and forget it?

I'm using SqlClient.SqlCommand object to run a few stored procs on my db. Normally when I run these manually via Query Analyzer they take up to 15 minutes to complete. So obviously when I run them using the SqlCommand object I get a SqlCommand timeout. I know I could set the timeout property to a very high number, but I'm wonderin...

Using SqlCommand Object in VB.NET

Can I use two command object with one open connection in one procedure at VB.NET? ...

Stored Proc and SqlCommand Timeout

If I run a stored proc using the SqlCommand and the SqlCommand times out does the StoredProc continue to execute or does it get force to quit when the SqlCommand disconnects? ...

How to extract the Sql Command from a Complied Linq Query

In normal (not compiled) Linq to Sql queries you can extract the SQLCommand from the IQueryable via the following code: SqlCommand cmd = (SqlCommand)table.Context.GetCommand(query); Is it possible to do the same for a compiled query? The following code provides me with a delegate to a compiled query: private static readonly ...

Two SqlCommand Objects and Updating One Source Table

I have two update sql statements for two SqlCommand object to update one DataTable with DataSet object to One Source Table. When I click on update button that's update only the first one and the second SqlCommand Object doesn't work. What's it? DataTable didn't support two Command object at one time? I write as follow: Dim conxMain As N...

Is SqlCommand.Dispose() required if associated SqlConnection will be disposed?

I usually use code like this: using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString)) { var command = connection.CreateCommand(); command.CommandText = "..."; connection.Open(); command.ExecuteNonQuery(); } Will my command automatically disposed? Or not and I have to wr...

Retrieve SqlCommand/OleDbCommand query after inserting parameters?

Is there any way to access the prepared statement as sent to the SQL server? Dim params(1) As OleDb.OleDbParameter params(0) = New OleDb.OleDbParameter("@ID", OleDb.OleDbType.VarChar, 50) params(0).Value = guiItemsGridView.Rows(e.RowIndex).Cells("ID").Value params(1) = New OleDb.OleDbParam...

Why do I get an Arithmetic overflow error converting numeric to data type numeric in ADO.NET?

Original Question: Why do I get an Arithmetic overflow error converting numeric to data type numeric in ADO.NET code using the Money Data Type when amount is greater than $999,999,99? Just as the question says... I have a bit of ADO.net code in the data access layer that talks to a Sql Server 2008 database. There is an Amount column...

C# Update Table using SqlCommand.Parameters

I'm trying to update an MSSQL table using SqlCommand, I think it's a syntax error with my T-SQL, but here is what I have so far: SqlCommand sqlCmd = new SqlCommand("UPDATE yak_tickets SET email = @emailParam, subject = @subjectParam, text = @textParam, statusid = @statusIDParam, ticketClass = @ticketClassParam WHERE id = @ticketIDParam"...

C# Update Table using SqlCommand.Parameters ASP.NET

Possible Duplicate: C# Update Table using SqlCommand.Parameters I'm trying to update an SQL Server table using SqlCommand, I think it's a syntax error with my T-SQL, but here is what I have so far: SqlCommand sqlCmd = new SqlCommand( "UPDATE yak_tickets SET email = @emailParam, subject = @subjectParam, text = @textParam...

What happens to Unicode in a System.Data.SQLCommand

Hello all. I have a SQLCommand : "Update Customers Set Name = @name where code = @code" and this code: cmd.Parameters[0].Value = "بهروز";//(some Unicode characters) cmd.Parameters[1].Value = 1; cmd.ExecuteNonQuery(); or this code: UpdateCommand.CommandText = "UPDATE [Customers] SET [Name] = @p1 WHERE (([Code]...

C# SqlDataReader Execution Statistics and Information

Hi, I am creating an automated DB Query Execution Queue, which essentially means I am creating a Queue of SQL Queries, that are executed one by one. Queries are executed using code similar to the following: using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString)...

Why does a SqlException thrown by SqlCommand.ExecuteNonQuery contain all the PRINTs as errors?

Hello! When I run the following snippet try { using (SqlConnection conn = new SqlConnection("I'm shy")) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "PRINT 'A';PRINT 'B';PRINT 'C';RAISERROR('SQL_Error', 18, 1)"; cmd.ExecuteNonQuery(); } } } catch (SqlException ex) { MessageBox.Show...

SQLCacheDependency with SqlCommand never null

I need to implement cache dependency on a sql select command that selects one value (latest modified date of some rows). My problem is that although I update the content and when I run the query manually, I see the new date, the system doesn't think it changed and doesn't refresh the content. object Taxonomy = GetTaxonomy(); ...