Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataRow Error? Not accessible because protected

Status
Not open for further replies.

djsuperz

IS-IT--Management
Jan 25, 2004
37
US
I get this error:
System.data.datarow.protected sub New(builder as system.data.datarowbuilder)' is not accessible in this context because its 'Protected'.

This Dr is underlined in my code:
Dim dr As New System.Data.DataRow


Here is my code:


Dim sqlconnectionstring As String = "Data Source=Server;User ID=adminassword=lalalaersist Security Info=False;Initial Catalog=Oasis"
Dim SqlConn As New System.Data.SqlClient.SqlConnection(sqlconnectionstring)
Dim strTrackingSheet As String = "Select * from Trackingsheet"
Dim datrackingsheet As New System.Data.SqlClient.SqlDataAdapter(strTrackingSheet, sqlconnectionstring)
Dim dsPatient As New System.Data.DataSet
Dim dtNewPat As New System.Data.DataTable
Dim dr As New System.Data.DataRow
SqlConn.Open()
datrackingsheet.Fill(dsPatient, "TrackingSheet")
SqlConn.Close()
Dim PatCB As System.Data.SqlClient.SqlCommandBuilder = New System.Data.SqlClient.SqlCommandBuilder(datrackingsheet)


Anyone know whats goin on? thanks
 
You can not create a new datarow by itself. The table has to create the row because a row cannot stand on its own. It must be part of a table.Kind of tricky at first.

Try

dr = dtNewPat.NewRow(); or something like that.

PS you don't need to do that to fill the table




 
I did it and i still get the same error message
 
get rid of this line all together

Dim dr As New System.Data.DataRow
 
Ok i removed it. What do i declare dr as?
 
You don't need it to fill the dataset. What else are you try to do?

 
I got it to work correctly, i was just trying to add a row to my database. Now i want to delete a row. I followed an online tutorial but it seems to not work correctly. It gives me an error: Object reference not set to an instance of an object.

Here is my code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlconnectionstring As String = "Data Source=Server;User ID=admin;Password=lalala;Persist Security Info=False;Initial Catalog=Oasis"
Dim SqlConn As New System.Data.SqlClient.SqlConnection(sqlconnectionstring)
Dim strTrackingSheet As String = "Select * from Trackingsheet"
Dim datrackingsheet As New System.Data.SqlClient.SqlDataAdapter(strTrackingSheet, sqlconnectionstring)
Dim dsPatient As New System.Data.DataSet
Dim dtNewPat As New System.Data.DataTable
Dim PatCB As System.Data.SqlClient.SqlCommandBuilder = New System.Data.SqlClient.SqlCommandBuilder(datrackingsheet)
Dim strSQL As String = "SELECT First, Last FROM Trackingsheet"
Dim SqlComm As New System.Data.SqlClient.SqlCommand(strSQL, SqlConn)
Dim Reader As System.Data.SqlClient.SqlDataReader
Try
sqlconn.Open()
Dim command As String

'set up an SQL delete
command = "delete from TrackingSheet where First = 'Troy'"
datrackingsheet.DeleteCommand.CommandText = command
'do the delete
datrackingsheet.DeleteCommand.ExecuteNonQuery()
ListBox1.Items.Clear()
ListRefresh()
Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
SqlConn.Close()
End Try

End Sub


Any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top