JameMeck
asked on
How to use SqlCommand with Silverlight.
I have some labels in my silverlight application, and I want to get data from SQL server for this label text.
How can I do that?
Something's like this with C#:
How can I do that?
Something's like this with C#:
mySqlConnection = new SqlConnection(ConnectionString);
SqlDataReader myReader = null;
string sql = "select isnull(sum(Quantity),0) Quantity from Inventory where [Type] = 'Primary'";
string sql2 = "select isnull(sum(Quantity),0) Quantity from Inventory where [Type] = 'Secondary'";
SqlCommand mySqlCommand = new SqlCommand(sql + ";" + sql2, mySqlConnection);
try
{
mySqlConnection.Open();
myReader = mySqlCommand.ExecuteReader();
while (myReader.Read())
{
RemainingPrimary.Text = myReader["Quantity"].ToString();
}
myReader.NextResult();
while (myReader.Read())
{
RemainingSecondary.Text = myReader["Quantity"].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show("Can't Get Data" + ex.Message);
}
finally
{
if (myReader != null)
myReader.Close();
if (mySqlConnection.State == ConnectionState.Open)
mySqlConnection.Close();
}
At first glance, everything looks OK. Are you getting an exception?
ASKER
My application is silverlight.
Those codes for WPF, I cannot run them with silverlight.
Those codes for WPF, I cannot run them with silverlight.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.