Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / September 2007

Tip: Looking for answers? Try searching our database.

i can't relate...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
radiolandog - 09 Sep 2007 22:38 GMT
I have two tables, list and songs.  The songs table contains columns such as
'songnumber', 'name', 'path' and 'filename'.
The list table contains columns 'listnumber' (identity) and  'A', 'B', 'C',
etc... that contain songnumbers.

I have a form with a databound combo box where we select the list.  Once the
list is selected, I'd like to get the 'name' of the song that is referenced
in the 'A' column of the list and make it be the label of a button.

That's where I get stuck...  I have a couple of questions from my various
attempts at getting un-stuck...

How do I reference the songnumbers in the list table?  I was trying this:
    audioDataSet.songs.nameColumn.ToString();

...but that just returned the name of the column, not the data.

If I ever do get the songnumbers, I have made a stored procedure to get the
info for each song.  Do I need to create a SqlCommand object in order to run
the SP, or is there one that already exists from the tableadapter?  What is
the best way to call the SP?

Thanks,
-dog

.
Linda Liu [MSFT] - 10 Sep 2007 09:05 GMT
Hi,

> How do I reference the songnumbers in the list table?

If you bind the ComboBox to the list DataTable by setting the DataSource
property of the ComboBox, you could get the value of the songnumber as
follows:

DataRowView drv = comboBox1.SelectedItem as DataRowView;
int songNumber = drv["A"];

> What is the best way to call the SP?

We usually use a SqlCommand object to execute a Stored Procedure. We can
configure a SqlCommand object at either design time or run time.

To configure a SqlCommand object at design time, add a SqlCommand objec e.g
to a form and set the CommandType property to StoredProcedure and the
CommandText property to the name of the Stored Procedure you want.

If you want to do this at run time, you could write code similar to the
following sample:

SqlConnection con = new SqlConnection("data source =.\\sqlexpress; initial
catalog = TestDataBase;Integrated Security=true");
SqlCommand comm = new SqlCommand();
comm.Connection = con;
comm.CommandText = "MySP";
comm.CommandType = CommandType.StoredProcedure;
con.Open();          
comm.ExecuteNonQuery();
con.Close();

Of course, if there's a resultset returned from the Stored Procedure, you
could create a SqlDataAdapter object and set its SelectCommand property to
the SqlCommand object and then call the Fill method of the SqlDataAdapter
object to fill the returned resultset to a DataTable.

In addtion, if the row count of the song table is not very large, I
recommend you to fill all the data from the song table to a DataTable. As
soon as you get the songnumber of the ComboBox selected item, you could
find the corresponding data row in the song DataTable and get the 'name' of
the song, which is more efficient. The following is a sample:

DataRowView drv = comboBox1.SelectedItem as DataRowView;
int songNumber = drv["A"];
DataRow dr = ds.Tables[0].Rows.Find(songNumber);
string songName = dr["name"];

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.