Hi,
[quoted text, click to view] > 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"];
[quoted text, click to view] > 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.