View Single Post
  #3 (permalink)  
Old May 14th, 2014, 07:55 AM
meme meme is offline
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi there,

You're never executing your SQL command or deal with the results. All you do is declare the command, but the SQL statement will never be fired against the database.

Take a look at this tutorial to see how to execute the command, and deal with its return value: http://www.csharp-station.com/Tutori...otNet/lesson03

Cheers.

Imar
imar, i tried this already, but still not working .
this is my code

<code> Page page = HttpContext.Current.Handler as Page;
if
(page != null)
{
string message = "Limit stock has been reached!";
ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + message + "');", true);
}
}



class SqlCommandDemo
{
SqlConnection conn;

public SqlCommandDemo()
{
// Instantiate the connection
conn = new SqlConnection("Data Source=MELINA_YEO-VAIO; Initial Catalog=InventorySystem; Integrated Security=True");
}



protected void ReadData(object sender, EventArgs e)
{
SqlDataReader rdr = null;

try
{

conn.Open();


SqlCommand cmd = new SqlCommand("Select case when (P_Amount <= SafetyStockamount) then 'Limit stock has been reached' end as Alert from Product", conn);


rdr = cmd.ExecuteReader();


while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
finally
{

if (rdr != null)
{
rdr.Close();
}

if (conn != null)
{
conn.Close();
}
}
}
}
}</code>

but when i execute the page does not show up @@
do i do sth wrong again with this ?
Reply With Quote