Solved

How to use SqlCommand with Silverlight.

Posted on 2011-02-13
3
1,035 Views
Last Modified: 2013-12-17
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#:

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();
			}

Open in new window

0
Comment
Question by:JameMeck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34886744
At first glance, everything looks OK. Are you getting an exception?
0
 

Author Comment

by:JameMeck
ID: 34894770
My application is silverlight.
Those codes for WPF, I cannot run them with silverlight.

0
 
LVL 7

Accepted Solution

by:
kovilpattiBalu earned 500 total points
ID: 34896125
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question