Returning a value of a DataBound ComboBox

Hi,

I have manage to DataBind the contents of ComboBox. The following code fills the comboBox with a list of Bed numbers:

<Page.Resources>

<DataTemplate x:Key="BedNo" >

<ComboBoxItem Content="{Binding Path=BedNo}"/>

</< FONT>DataTemplate>

</</Page.Resources>

<ComboBox ItemsSource="{Binding}" ItemTemplate="{DynamicResource BedNo}" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left" Width="48" Height="20.92" x:Name="BedNO" />

I then want to use the current selected value from that ComboBox in my SQL statement:

AddToIPU()

{

SqlConnection conn = new SqlConnection(SqlConnection1);

conn.Open();

String Bed = this.BedNO.text;

int ID = SqlConnections.locateReferralNo(11111);

string updateIPUData = "UPDATE IPUData SET lengthOfStay=" +

"'" + this.lengthofStay.Text + "', " +

"dateAdmitted =" +

"'" + date + "', " +

"ReferralID =" +

"'" + ID + "'" +

"WHERE BedNo = " + "'" + Bed + ";'";

SqlCommand cmd8 = new SqlCommand(updateIPUData, conn);

cmd8.ExecuteNonQuery();

}

This code falls over because the current value of the Bed string is 'System.Data.DataRowView' when it should be a bed number.

I have tried some variations on the .text on the BedNO comboBox but nothing seems to be working??

Thanks in advance, Tom

[1558 byte] By [Tom2505] at [2008-2-18]

Visual Studio Orcas

Site Classified