Click here to Skip to main content
12,301,437 members (60,493 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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 20:25pm
Edited 30-Aug-12 20:33pm
Mehdi Gholam308.3K
v2
Comments
ryanb31 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

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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160525.2 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2016
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