Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jhermiz
3564 Posts |
Posted - 2004-09-27 : 16:21:58
|
I am trying to update a row in my db...if I do: If Me.ddlRepresentative.SelectedItem.Value Is Nothing Then .Parameters.Add("@Representative", SqlDbType.VarChar).Value = "" Else .Parameters.Add("@Representative", SqlDbType.VarChar).Value = Me.ddlRepresentative.SelectedItem.Value End If It throws an exception...how can I tell it that if there is no value in ddlRepresentative then to store nothing or null...It cant even pass the if condition that is where it blows up.Thanks. |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-09-27 : 16:26:00
|
.Parameters.Add("@Representative", SqlDbType.VarChar).Value = Nothing<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-27 : 16:28:42
|
But it dies on the if...All I want to say is if there is a value in ddlRepresentative than store that value...if there is nothing dont store anything...But If I get rid of the if it errors out..if I keep the if it throws an exception... |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-09-27 : 16:28:54
|
is this part If Me.ddlRepresentative.SelectedItem.Value Is Nothing Then causing the exception? not sure if that is legal .... is ddlRepresentative a listbox?if so, try:If Me.ddlRepresentative.SelectedItem.SelectedIndex = -1 Then ... - Jeff |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-09-27 : 16:29:50
|
by the way -- remember in T-SQL "" is not the same as NULL ....- Jeff |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-27 : 16:37:26
|
Hmm Jeff I did useIf Me.ddlRepresentative.SelectedIndex=-1 then..And the if worked however within that I did:.Parameters.Add("@Representative", SqlDbType.VarChar).Value = NothingAnd then I executed the query but it threw this error:An Error Occurred: System.Data.SqlClient.SqlException: Procedure 'update_registered_user' expects parameter '@Representative', which was not supplied. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at ims.jakah.com.profile.UpdateUser() in \\Jakah-iis-2\ims\profile.aspx.vb:line 303 I did provide that parameter but its value is "Nothing" |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-27 : 16:58:19
|
err now it works...i just need to be able to read that password in somehow:(I know ive seen that functionality before...on like forums..and then you can update it and confirm it... |
 |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-09-27 : 18:39:58
|
Me.ddlRepresentative.SelectedItem.Value fails if nothing is selected because SelectedItem is null, thus it has no .Value Property.You could also do:If Me.ddlRepresentative.SelectedItem Is Nothing Then .Parameters.Add("@Representative", SqlDbType.VarChar).Value = "" Else If Me.ddlRepresentative.SelectedItem.Value Is Nothing .Parameters.Add("@Representative", SqlDbType.VarChar).Value = "" Else .Parameters.Add("@Representative", SqlDbType.VarChar).Value = Me.ddlRepresentative.SelectedItem.Value End IfEnd If -Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
|
|
|
|