??????? InvalidCastException ??? ?????? ??? ???? DataColumn ?? NULL

?????? ????????? ?????? ?????????
???? ???????: 310371 - ??? ???????? ???? ????? ????? ??? ???????.
???? ??? ??????? ??? ?????? ????? Microsoft .NET Framework ??? ????? ???????:
  • System.Data
  • System.Data.SqlClient
????? ???? | ?? ????

?? ??? ??????

???????

??? ?????? ???? DataColumn ?? NULL ? ???? ???????? ?? ???? ???? ???????.

????? ????? DataSet ????? ????????? ??????:
??? ??????? ??? ????? ?? ????? 'System.Data.StrongTypingException' ?? invalidcast.exe
??????? ??????: ?? ???? ?????? ??? ?????? ????? DBNULL.
???? ????? DataSet ????? ????????? ??????:
??? ??????? ??? ????? ?? ????? 'System.InvalidCastException' ?? microsoft.visualbasic.dll
??????? ??????: ???????? ?? ??? 'DBNULL' ??? ????? '?????' ??? ????.

?????

??? 1

??? ??????? ????? DataSet ???? ????????? ??? ?????? ??? ???? ?????? ??? NULL.

??? 2

??? ??????? ???? DataSet ???? ?????? NULL ???? ????? ???? ??? ?????? ??? ?? ????? NULL.

????

??? 1

?????? ?????? NULL ??? ?????? ??? ?????? ?????? ??. ?? ???? DataSet ? ?????? ??????? DataRow.IsNull. ?? ???? DataSet ? ?????? ??????? DataRow.IscolumnnameNull.

??? 2

??????? ????? ????? ???????? ???????? ????? ???? ????? NULL.

?????

????? ??? ?????? ??? ???????.

??????? ????

????? ????? ????? ??????

  1. ??? ????? Microsoft Visual Studio .NET.
  2. ????? ????? ????? Windows ???? ?? Visual Basic .NET. ??? ????? Form1 ??? ??????? ???? ???????.
  3. ???? ?? ?? ????? ??????? ??? ???? ??? ????? ????? System.Data.
  4. ?? ???? ???? ?? ?? Form1.
  5. ????? ????? ??? ???? ??? btnUntype ???????? ???? ??? Untype.
  6. ??????? ??????? ?????? ????????? ?? ????? ??? ?????? ?????? System.Data ???? ??? ?????? ????? ????????? ?? ????? ??????? ?????? ?? ????????? ????????. ????? ????????? ???????? ??????? ??? ???? "Declarations ???" Form1:
       Imports System
       Imports System.Data
       Imports System.Data.SqlClient
    					
  7. ?? ?????? ????????? ???????? ??????? ?? ????? btnUntype:
            Dim str As String
            Dim ds As New DataSet()
            Dim r As DataRow
            Dim con As New SqlConnection("server=myserver;integrated security=sspi;database=northwind")
            Dim da As New SqlDataAdapter("select * from customers where customerid='ANTON'", con)
            da.Fill(ds, "customer")
            r = ds.Tables(0).Rows(0)
            'Uncomment to check for Null. 
            'If r.IsNull("fax") Then
            '   MessageBox.Show("Value is Null")
            'End If
            str = r("fax") 'Comment line to check for Null.
            MessageBox.Show(str) 'Comment line to check for Null.
            
    					
  8. ????? ????? ??????? (myserver) ???? ?????? ??????? ?????? ?????? ??.
  9. ??? ??????? ????? ??. ?? ??????? ????? ? ???? ??? ???? ????? ???????.
  10. ???? ??? Untype. ???? ????????? ??????? ???????? ???? DataSet.
  11. uncomment ???? IF ? ?? ??????? ???? ???? ????? IF ?????? ?? ???? NULL.
  12. ??? ??????? ????? ??. ?? ??????? ????? ? ???? ??? ???? ?? ?? ?????? ???????. ???? ?? ???? ???? ??????? "?????? ?? Null".
  13. ?? ???? ???? ?? ??? ?? Form1.
  14. ????? ????? ??? ???? ??? btntype ???????? ???? ??? ???.
  15. ????? ???? DataSet ???????? ???? ??????? ?? ????? ?????? Northwind. ????? ????? SQLDataAdaptersqlda.
  16. ?? ?????? ????????? ???????? ??????? ??? ????? btntype:
            sqlda.Fill(DataSet11)
            Dim str As String
            Dim int As Integer
            Dim cust As DataSet1.CustomersRow
            cust = DataSet11.Customers.Rows(0)
            'Uncomment to catch null values.  
            'If cust.IsFaxNull Then
            '    MessageBox.Show("Value is Null")
            'End If
            str = cust.Fax() 
            MessageBox.Show(str)
            '    Comment line to check for Null.
    					
  17. ?? ?????? ??????? ?? ???? ??? ???? ???. ???? ?????????.
  18. uncomment ???? If... Then ?? ????????? ???????? ??? ?? ????? ????????? ???? ????????? ????????.
  19. ??? ???????? ??? ?? ?? ?????? ??????? ????? ???? ???????.

?????

?????? ??? ???? ?? ????????? ??? ????? DataSet ????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
315678????? ????? ??????? DataSet ????? ???????? Visual Basic .NET
????? ?? ????????? ??? ADO.NET ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
313590????? ?? ADO.NET

???????

???? ???????: 310371 - ????? ??? ??????: 09/???/1428 - ??????: 2.7
????? ???
  • Microsoft ADO.NET 2.0
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
????? ??????: 
kbmt kbprb kbsystemdata KB310371 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????310371

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com