Thanks guys for the help :-)
----- Original Message -----
From: Mark E
To: [EMAIL PROTECTED]
Sent: Tuesday, October 12, 2004 5:37 PM
Subject: Re: [AspNetAnyQuestionIsOk] Cast from type 'DBNull' to type 'String' is not
valid
You are trying to convert a NULL value (IDC parameter) to a string. You can't do
that.
Change this line from:
e_id = CStr(cmd.Parameters("@IDC").Value)
To:
If Not IsDBNull(cmd.Parameters("@IDC").Value) Then
e_id = CStr(cmd.Parameters("@IDC").Value)
Else
e_id = "0"
End if
Mark
Avital Katz <[EMAIL PROTECTED]> wrote:
Hi,
I receive an error -Cast from type 'DBNull' to type 'String' is not valid.
- when i tried to insert a new line to the database in sql server.
What could be the reason?
Thanks
aspx.vb code:
Dim strIn As String = "SET dateformat dMy; INSERT INTO ESTATE
(Status_Id,Classify_Id,type_id,floor_id,price,ZONE_ID,Area_Id,City_Id,room_id,AreaSize,toilet,e_description,AdStat_Id,parents_unit,garden,garden_size,balcony,balcony_size,parking,elavator,estate_age,entrance_date,sale,parkingtype_id,parking_qty,urgent,built_area,address)
values
(@STATUS_ID,@CLASSIFY_ID,@TYPE_ID,@FLOOR_ID,@PRICE,@ZONE_ID,@Area_Id,@CITY_ID,@ROOM_ID,@AREASIZE,@toilet,@E_DESCRIPTION,@ADSTAT_ID,@parents_unit,@garden,@garden_size,@balcony,@balcony_size,@parking,@lift,@estate_age,@entrance_date,@sale,@parking_type,@parking_qty,@urgent,@built_area,@address);"
+ "Select @IDC=@@IDENTITY"
cmd = New SqlCommand(strIn, oConn)
cmd.Parameters.Add("@STATUS_ID", drpStatus.SelectedItem.Value)
cmd.Parameters.Add("@CLASSIFY_ID", drpClass.SelectedItem.Value)
cmd.Parameters.Add("@TYPE_ID", drpType.SelectedItem.Value)
cmd.Parameters.Add("@PRICE", txtPrice.Text)
cmd.Parameters.Add("@Area_ID", "")
cmd.Parameters.Add("@CITY_ID", drpCity.SelectedItem.Value)
cmd.Parameters.Add("@ZONE_ID", drpArea.SelectedItem.Value)
cmd.Parameters.Add("@ROOM_ID", drpRooms.SelectedItem.Value)
cmd.Parameters.Add("@parents_unit", parents)
cmd.Parameters.Add("@FLOOR_ID", drpFloor.SelectedItem.Value)
cmd.Parameters.Add("@AREASIZE", txtArea.Text)
cmd.Parameters.Add("@toilet", txtToilet.Text)
cmd.Parameters.Add("@garden", garden)
cmd.Parameters.Add("@garden_size", txtGarden.Text)
cmd.Parameters.Add("@balcony", balcony)
cmd.Parameters.Add("@balcony_size", txtBalcony.Text)
cmd.Parameters.Add("@parking", parking)
cmd.Parameters.Add("@lift", lift)
cmd.Parameters.Add("@E_DESCRIPTION", txtDescription.Text)
cmd.Parameters.Add("@estate_age", txtAge.Text)
cmd.Parameters.Add("@entrance_date", txtDate.Value)
cmd.Parameters.Add("@ADSTAT_ID", drpAdStat.SelectedItem.Value)
cmd.Parameters.Add("@sale", sale)
cmd.Parameters.Add("@parking_type", parking_type)
cmd.Parameters.Add("@parking_qty", parking_qty)
cmd.Parameters.Add("@urgent", urgent)
cmd.Parameters.Add("@built_area", txtBuilt.Text)
cmd.Parameters.Add("@address", txtAddress.Text)
cmd.Parameters.Add("@IDC", SqlDbType.Int)
cmd.Parameters("@IDC").Direction = ParameterDirection.Output
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
lblerror.Text = "Insert failed"
End Try
e_id = CStr(cmd.Parameters("@IDC").Value)
The error that I get is:
Exception Details: System.InvalidCastException: Cast from type 'DBNull' to type
'String' is not valid.
Source Error:
Line 939:
Line 940: End Try
Line 941: e_id = CStr(cmd.Parameters("@IDC").Value)
[Non-text portions of this message have been removed]
Yahoo! Groups SponsorADVERTISEMENT
---------------------------------
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]
Yahoo! Groups Sponsor
ADVERTISEMENT
------------------------------------------------------------------------------
Yahoo! Groups Links
a.. To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
b.. To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/