C
cm@gowcity
IM AM NEW TO WEB SERVICE AND C# AND HAVE A QUESTION / PROBLEM
MY SIMPLE WEB METHOD
[WebMethod]
public string logtime(string ClientUserName)
{
try
{
SqlConnection sqlConn = new SqlConnection(
"data source=localhost;" +
"initial catalog=isa;integrated security=true");
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = "SELECT logTime FROM WebProxyLog " +
"WHERE ClientUserName = '" + ClientUserName + "'";
sqlCmd.Connection = sqlConn;
sqlConn.Open();
string logtime = (string)sqlCmd.ExecuteScalar();
sqlConn.Close();
return logtime;
}
catch(Exception e)
{
throw new Exception("Error calculating cost: " + e.Message);
}
}
NOW THIS RETURNS THE FIRST ELEMENT FROM THE SET RETURNED FROM THE
QUERY (ITHINK) BECAUSE I AM USING EXECUTESCALAR?
HOW COULD I MODIFY THIS TO RETURN ALL INSTANCES SO MY CLIENT
APPLICATION CAN ITERATE THROUGH EACH?
HOPE SOMEBODY HAS TIME FOR A NEWBIE
THANKS IN ADVANCE
COLIN
MY SIMPLE WEB METHOD
[WebMethod]
public string logtime(string ClientUserName)
{
try
{
SqlConnection sqlConn = new SqlConnection(
"data source=localhost;" +
"initial catalog=isa;integrated security=true");
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = "SELECT logTime FROM WebProxyLog " +
"WHERE ClientUserName = '" + ClientUserName + "'";
sqlCmd.Connection = sqlConn;
sqlConn.Open();
string logtime = (string)sqlCmd.ExecuteScalar();
sqlConn.Close();
return logtime;
}
catch(Exception e)
{
throw new Exception("Error calculating cost: " + e.Message);
}
}
NOW THIS RETURNS THE FIRST ELEMENT FROM THE SET RETURNED FROM THE
QUERY (ITHINK) BECAUSE I AM USING EXECUTESCALAR?
HOW COULD I MODIFY THIS TO RETURN ALL INSTANCES SO MY CLIENT
APPLICATION CAN ITERATE THROUGH EACH?
HOPE SOMEBODY HAS TIME FOR A NEWBIE
THANKS IN ADVANCE
COLIN