Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: ExecuteNonQuery


Message #1 by "DT-Rene Vazquez" <renevazquez@c...> on Fri, 20 Dec 2002 10:39:15 -0500
Hi all, I am querying SQL through the following code:
 
StringBuilder TempBuilder = new StringBuilder();
                  TempBuilder.Append("SELECT table_name from
information_schema.tables WHERE table_name='");
                  TempBuilder.Append(this.Name);
                  TempBuilder.Append("'");
// this.Name is a property of the calss from which the code is.
                  SqlCommand TempCommand = new
SqlCommand(TempBuilder.ToString(), SqlConn);
                  int TempInt = TempCommand.ExecuteNonQuery();
                  return (TempInt==1);
 
if I execute the command The tempint gets the value -1 wether or not the
table exist in the  information_schema.tables view. If I run the same
sql script in the query analyzer it returns one row for a table that
exists and 0 if it does not. I also debug the code and the command text
got exactly the text that I execute in the query analyzer.
 
Anyone have an idea of what I am doing wrong, thanks a lot for the help.

Message #2 by "Brian Smith" <bsmith@l...> on Fri, 20 Dec 2002 16:56:45 -0000
ExecuteNonQuery means exactly that - execute some SQL that does NOT
perform a SELECT. Yours does. 
If you only want to check for existence then try:
	IF EXISTS (SELECT table_name from ....) RETURN 1;

brian

-----Original Message-----
From: DT-Rene Vazquez [mailto:renevazquez@c...] 
Sent: Fri, 20 Dec 2002 15:39
To: ADO.NET
Subject: [ado_dotnet] ExecuteNonQuery


Hi all, I am querying SQL through the following code:
 
StringBuilder TempBuilder = new StringBuilder();
                  TempBuilder.Append("SELECT table_name from
information_schema.tables WHERE table_name='");
                  TempBuilder.Append(this.Name);
                  TempBuilder.Append("'");
// this.Name is a property of the calss from which the code is.
                  SqlCommand TempCommand = new
SqlCommand(TempBuilder.ToString(), SqlConn);
                  int TempInt = TempCommand.ExecuteNonQuery();
                  return (TempInt==1);
 
if I execute the command The tempint gets the value -1 wether or not the
table exist in the  information_schema.tables view. If I run the same
sql script in the query analyzer it returns one row for a table that
exists and 0 if it does not. I also debug the code and the command text
got exactly the text that I execute in the query analyzer.
 
Anyone have an idea of what I am doing wrong, thanks a lot for the help.


===
Fast Track ADO.NET with C# is a concise introduction to the concepts,
techniques, and libraries that you will need in order to start using
ADO.NET in your applications. The book covers DataSets and Typed
DataSets, accessing data using DataReaders and DataAdaptors, the close
relationship between ADO.NET and XML, how and where to use ADO.NET in
your enterprise applications, and how to use Web Services and ADO.NET to
easily pass data between applications.
http://www.wrox.com/books/1861007604.htm

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 17/12/2002
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 17/12/2002
 


  Return to Index