---
title: "Updating query with comparison between string and varchar(max)"  
description: "Updating query with comparison between string and varchar(max)"  
author: "Kate Smith"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1210/updating-query-with-comparison-between-string-and-varchar-max  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# Updating query with comparison between string and varchar(max)

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs),\
I have an updating query like this:\
**[public void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) Update_Download(string _url){** **Data.Connect();** **using (Data.connexion)** **{** **string [queryString](https://www.mindstick.com/interview/123/what-is-querystring-benefits-and-limitations-of-using-querystring) = "update Fichier set Last_download=@last , Downloads_count= Downloads_count + 1 where Url = @url ";** **[SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) command = new SqlCommand(queryString, Data.connexion);** **command.Parameters.AddWithValue("@last", DateTime.Now);** **command.Parameters.AddWithValue("@url", _url);** **try** **{** **SqlDataReader reader = command.ExecuteReader();** **}** **catch { }** **}** **}** **}****}**\
the string [connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi) :\
**public static [SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) connexion;** **public static bool Connect()** **{** **System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();** **builder["Initial Catalog"] = "Upload";** **builder["[Data Source](https://www.mindstick.com/interview/808/what-is-a-data-source)"] = "bd";** **builder["[integrated Security](https://www.mindstick.com/forum/159040/what-is-the-difference-between-integrated-security-true-and-integrated-security-sspi)"] = true;** **string connexionString = builder.ConnectionString;** **connexion = new SqlConnection(connexionString);** **try { connexion.Open(); return true; }** **catch { return false; }** **}** **public static void Disconnect()** **{** **if (connexion != null) connexion.Close();** **connexion = null;** **}**\
the query is executing without exception but nothing is changed in table. the type of the attribute Url is varchar(Max) and the DBMS is [Sql Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server).\
So what is the problem? how can i correct my query?\

## Replies

### Reply by Sumit Kesarwani

Hi,\
The problem is that you're using an **ExecuteReader** command. Change that to this:\
**command.ExecuteNonQuery();**Now, on top of that, I want to offer some advice. Consider the following modification of your current code:\
**public void Update_Download(string _url)****{** **try** **{** **using (SqlConnection connexion = Data.Connect())** **{** **string queryString = "update Fichier set Last_download=@last , Downloads_count= Downloads_count + 1 where Url = @url ";****\** **using (SqlCommand command = new SqlCommand(queryString, connexion))** **{** **command.Parameters.AddWithValue("@last", DateTime.Now);** **command.Parameters.AddWithValue("@url", _url);** **command.ExecuteNonQuery();** **}** **}** **}** **catch (Exception ex)** **{** **}****}**and consider having Data.Connect() return a new SqlConnection(...) because you want to follow that procedure. When you need a new connection, get one using the new operation, and let SQL Server manage the pooling. Never share connections.\
I'm not sure you are sharing connection, this is just an observation.\


---

Original Source: https://www.mindstick.com/forum/1210/updating-query-with-comparison-between-string-and-varchar-max

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
