2014年7月13日 星期日

[RESOLVED] Dropdown Insert Issue


Im using 3 dropdown lists on my form. The dropdown displays the Data Text field, but I want to pass the Data Value field to the database. The database has Int field types, so I want to insert the ID from the data value field (the store number). Here is one
of the drop down lists:


                        DataTextField="StoreName" DataValueField="StoreNumber">

ConnectionString="<%$ ConnectionStrings:AdminConnectionString %>"
SelectCommand="SELECT DISTINCT [StoreName], [StoreNumber] FROM [Stores]">

In my code, I ref the dropdown on my form like this:


cmd.Parameters.Add("@StoreID", SqlDbType.Int).Value = DdlStore.DataValueField

But this throws: Error: Failed to convert parameter value from a String to a Int32. Help appreciated. Thanks.



Hi Report


DdlStore.DataValueField

in this field may be string value are came not came then use


cmd.Parameters.Add("@StoreID",
SqlDbType.Int).Value
= Convert.ToInt32(DdlStore.DataValueField);


i am not quite sure about this may be it DdlStore.Item.SelectedValue
please check this one also


hope this will help you




Use the DDL's SelectedValue:


cmd.Parameters.Add("@StoreID", SqlDbType.Int).Value = DdlStore.SelectedValue

Or:


cmd.Parameters.AddWithValue("@StoreID", DdlStore.SelectedValue)




 


 



cmd. Parameters .AddWithValue( "@StoreID" ,Convert.ToInt 32( DdlStore.SelectedValue));

沒有留言:

張貼留言