Solved

How to use SqlCommand with Silverlight.

Posted on 2011-02-13
3
1,007 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
3 Comments
 
LVL 74

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now