Reputation:
I add values in property in combobox at Collection. Like this.
I want when select 1 items and click button save. I will save into database.
Button Save
is:
CameraDTO obj = new CameraDTO();
obj.DefaultCam = Convert.ToInt16(cbxDefaultCam.Items.ToString());
CameraBUS.CameraInsert(obj);
In CameraBUS.CameraInsert
is:
public void Camera_Insert(CameraDTO data)
{
using (var cmd = new SqlCommand("sp_Camera_Insert", GetConnection()))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@DefaultCam", data.DefaultCam));
cmd.ExecuteNonQuery();
}
}
Following is the error am getting while executing.
Upvotes: 0
Views: 49
Reputation: 29006
cbxDefaultCam.Items
returns a collection of ComboBoxItem
. it cannot be converted to string using .ToString()
or even Convert.To..()
instead for this you can use any of the following based on your use.
cbxDefaultCam.SelectedItem.Text
<-- which gives the bounded text field cbxDefaultCam.SelectedValue
<-- which gives the bounded value field Upvotes: 1