Click here to Skip to main content
11,477,625 members (76,386 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Oracle VB.NET
Respected all,
I am trying to insert values in oracle using my vb.net application but when i run my application then i got following error message
"Object reference not set to an instance of an object."

if i use new keyword to "dim dsNewRow As New DataRow" then i got following error message
"Error	2	'System.Data.DataRow.Protected Friend Sub New(builder As System.Data.DataRowBuilder)' is not accessible in this context because it is 'Protected Friend'."

what i can do please help me
Following is my code
sql = "select * from shift_detail";
        ds = New DataSet
        da = New OracleDataAdapter(sql, cn)
        da.Fill(ds, "save")
        cn.Close()
        Dim cb As New OracleCommandBuilder(da)
        Dim dsNewRow As DataRow
 
        dsNewRow = ds.Tables("save").NewRow()
 
        dsNewRow.Item("shift_no") = newno("Select max(shift_no) from shift_detail")
        dsNewRow.Item("shift_nm") = shift_name
        dsNewRow.Item("edate") = dt
        dsNewRow.Item("status") = "R"
        dsNewRow.Item("code") = shift_code
 

        ds.Tables("save").Rows.Add(dsNewRow)
        da.Update(ds, "save")
Posted 30-Aug-12 21:25pm
Edited 30-Aug-12 21:33pm
Mehdi Gholam275.3K
v2
Comments
ryanb31 at 31-Aug-12 8:33am
   
You need to find which line of code is give you the first error. It's just telling you something is not set yet or you are trying to access a column that is not there.
Avi Mali at 31-Aug-12 9:02am
   
when my debugger is going to ds.Tables("save").Rows.Add(dsNewRow) line that time firs error is occur. My all column names are correct.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this, it might help
 Public Function InsertData(ByVal SQLString As String) As Integer
 strErrorMessage = ""
        Dim objCmd As OracleCommand = New OracleCommand
        Try
            NoofRowsAffected = objCmd.ExecuteNonQuery
            Return NoofRowsAffected
        Catch ex As Exception
            strErrorMessage = "Message :" & ex.Message
            Return Nothing
        Finally
            If Not IsNothing(objCmd) Then
                objCmd.Parameters.Clear()
                objCmd.Dispose()
                objCmd = Nothing
            End If
End Function
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 274
1 Richard Deeming 245
2 _duDE_ 165
3 Tomas Takac 150
4 Sascha Lefèvre 145
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,246
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100