Click here to Skip to main content
16,005,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
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
Updated 30-Aug-12 20:33pm
v2
Comments
ZurdoDev 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 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

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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900