$query = "SELECT DISTINCT * FROM itl WHERE city='$city2' AND
state='$state2'";
$temp = @mysql_query($query);
$result = $mysql_fetch_row($temp);
if (!$result) {
do something
}
else {
do something else
}
Main Topics
Browse All TopicsI need to query a database using a where clause and if/else conditional statement to test if something condition is false or true. I exactly needs the asp.net equivalent to the following PHP code.
$query = "SELECT DISTINCT * FROM itl WHERE city='$city2' AND
state='$state2'";
$result = @mysql_query($query);
if (!$result) {
do something
}
else {
do something else
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is all you need :)
http://www.codeproject.com
ex :
I tried using something like the following and got the error message
SqlDataReader dr = DataAccess.ExecuteReader(C
if (dr.Read())
{
//do something
}
else
{
//do something
}
Compiler Error Message: CS0103: The name 'DataAccess' does not exist in the current context
using System;
using System.Data;
using System.Data.SqlClient;
namespace DataLayer
{
/// <summary>
/// Summary description.
/// </summary>
public class DataAccess
{
#region Variables
private static string m_sOleDbConnectionString = "Data Source=servername;Initial Catalog=databasename;User Id=username;Password=passw
public static SqlConnection CurrentOleDbConnection;
#endregion
#region constructor
public DataAccess()
{
//
// TODO: Add constructor logic here
//
}
#endregion
#region Properties
/// <summary>
///
/// </summary>
public static string OleDbConnectionString
{
get { return m_sOleDbConnectionString; }
set { m_sOleDbConnectionString = value; }
}
#endregion
#region Method
/// <summary>
///
/// </summary>
public void OpenConnection()
{
try
{
if (CurrentOleDbConnection == null || CurrentOleDbConnection.Sta
{
CurrentOleDbConnection = new SqlConnection(m_sOleDbConn
// SMAPGlobal.WriteLog("Conne
CurrentOleDbConnection.Ope
//SMAPGlobal.WriteLog("Con
}
}
catch (Exception ex)
{
//SMAPGlobal.WriteLog("Can
throw ex;
}
}
/// <summary>
///
/// </summary>
public void CloseConnection()
{
try
{
if (CurrentOleDbConnection != null)
{
if (CurrentOleDbConnection.St
CurrentOleDbConnection.Clo
CurrentOleDbConnection.Dis
CurrentOleDbConnection = null;
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
///
/// </summary>
/// <param name="sSQL"></param>
/// <returns></returns>
public SqlDataReader ExecuteReader(string sSQL)
{
try
{
OpenConnection();
SqlCommand cmd = new SqlCommand(sSQL, CurrentOleDbConnection);
SqlDataReader reader = cmd.ExecuteReader();
cmd.Dispose();
return reader;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
///
/// </summary>
/// <param name="sSQL"></param>
/// <returns></returns>
public int ExecuteNonQuery(string sSQL)
{
try
{
int iResult = -1;
OpenConnection();
SqlCommand cmd = new SqlCommand(sSQL, CurrentOleDbConnection);
iResult = cmd.ExecuteNonQuery();
cmd.Dispose();
return iResult;
}
catch (Exception ex)
{
throw ex;
}
finally
{
CloseConnection();
}
}
#endregion
}
}
sorry my I still can't seem to this the about to work for what I need to do.... in a nut shell this is all I need to do... but I keeping getting a error on the "da.Read()" part on line 7
SqlConnection con2 = new SqlConnection();
con2.ConnectionString = "Data Source=myConnectionstring.
string str = "SELECT DISTINCT count(*) FROM itl itl WHERE city='$city2' AND state='$state2'";
con2.Open();
SqlDataAdapter da = new SqlDataAdapter(str, con2);
if (da.Read()) // i just want to test if a matching value was returned that I all.... very short and simply no need for looong lines of code
{
//do something
}
else
{
//do something
}
got it.....!!!!
SqlConnection con2 = new SqlConnection();
con2.ConnectionString = "Data Source=myConnectionstring.
string str = "SELECT DISTINCT count(*) FROM itl itl WHERE city='$city2' AND state='$state2'";
SqlCommand myCommand = new SqlCommand(str, con2);
con2.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
if (myReader.Read())
{
//do something
}
else
{
//do something
}
Thanks for all you help..... of course minus my newbeee ness...
Business Accounts
Answer for Membership
by: HoangTuDauMatPosted on 2009-11-03 at 08:39:16ID: 25730753
:)
Select allOpen in new window