Hi,
I have an ultracombo control that gets filled by a dataset. If I do not choose anything and press the save button the value of the combo equals 'default' and the SQL stored procedure gives an error as 'default' is passed instead of null.
How can I send a null value if nothing is selected?
Thanks.
I don't understand. What do you mean by "default"? Is this a string? If so, where is it coming from? The Combo doesn't default to some arbitrary string as it's value so this must be coming from something in your code or your data.
I am using SQL Server.
One of the parameteres in my form is an ultraCombo and I pass the following parameter when updating the record.
comm.Parameters.Add("@Surgeon", SqlDbType.BigInt).Value = cmbSurgeons.Value;
However this gives an error saying that stored procedure 'xxxx' expects parameter "@Surgeon" which was not supplied.
In SQL Profiler these are the values that are passed
exec tblSurgicalProcedure_INSERT @Patient = 1715, @PerformedDate = 'Dec 21 2007 5:20:41:000PM', @Surgeon = default, @Remarks = NULL
As you can see the @Surgeon got a value of 'default' instead of null.
I'm not that familiar with SQL Profiler, but I suspect that is an artifact of how the exec string is being built, not the value of the Combo. Have you tried examining the Value property of the combo to see what's actually being returned? I notice that 'default' here is not in quotes, so it looks like it's using this to indicate that the value has not been changed.
SQL Profiler shows all the commands that are executed against SQL Server. In my example I am executing a stored procedure, passing the parameters of that Stored Procedure.
I examined the value property in debug mode and its null. But its propably NOT the System.DBNull.value required from the database.
Regards,
Nicolas
Okay, but at least we have established that it's not "default". :)
I think what you need to do is set the DataSourceNullValue property on the Binding to DBNull.Value.
How can I do that?
DataSet ds = new DataSet();SqlDataAdapter da = new SqlDataAdapter(comm);da.Fill(ds);cmbSurgeons.DataSource = ds.Tables[0];
Hi Nicolas,
This can't be all of it... you started off this post saying that you are binding the Value property of the combo, didn't you? There's nothing here that does that. You are only binding the list portion of the combo here. That just populates the list. There is nothing here that even refers to the combo's Value.
cmbSurgeons.DataSource = ds.Tables[0];cmbSurgeons.ValueMember = "surgeonID";cmbSurgeons.DisplayMember = "Surgeon Name";cmbSurgeons.DisplayLayout.Bands[0].Columns[0].Hidden = true;cmbSurgeons.DisplayLayout.Bands[0].Columns[1].Width = 200;
The code you have here is populating the list. You must also be binding the Value using DataBindings.Add, right? This returns a Binding object.