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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error trying to create a SqlDataReader

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
Compiler Error Message: BC30390: 'System.Data.SqlClient.SqlDataReader.Private Overloads Sub New(command As System.Data.SqlClient.SqlCommand)' is not accessible in this context because it is 'Private'.

What does this mean? All I want to do is read the value of 'ScanSetup' from this one record. (The orderID is the primary key.) Where am I going wrong folks? Thanks.

For the time being, I've simply included my VB code, not the HTML attached, because it's not in error. To test this out you may need to create a few labels.
<%@ Page Language=&quot;VB&quot; %>
<%@ import Namespace=&quot;System.Data&quot; %>
<%@ import Namespace=&quot;System.Data.SqlClient&quot; %>
<script runat=&quot;server&quot;>

' Insert page code here
'

Sub Page_Load()
Dim strConn, strSql, orderID, filmType, scanSetup AS String
orderID = Request.Form(&quot;OrderID&quot;)
Dim objData As New sqlDataReader
Dim objConn As SqlConnection
Dim objCom As SqlCommand
strConn = &quot;server=Dell2400;database=DP2;uid=dp2user;password=dp2;&quot;
strSql = &quot;SELECT ScanSetup FROM Orders WHERE OrderID LIKE '&quot; & orderID & &quot;'&quot;
objConn = New SqlConnection(strConn)
objCom = New SqlCommand(strSql, objConn)
Try
objConn.Open()
objData = objCom.ExecuteReader()
scanSetup = RTrim(objData(&quot;ScanSetup&quot;))
objData.Close()
objConn.Close()
Catch e as Exception
ErrorMsg.Text = e.ToString()
End Try
if NOT scanSetup = &quot;&quot; then
Select Case scanSetup
Case &quot;WED LR 120/220 6x6 (SBA)&quot;
filmType = &quot;Wed6x6&quot;
Case &quot;WED LR 120/220 6x7 (SBA)&quot;
filmType = &quot;Wed6x7&quot;
Case Else
ErrorMsg.Text = &quot;There was no film type defined for this order.&quot;
End Select
end if
if IsPostBack then Label1.Text = &quot;changes.&quot;
End Sub

</script>
 
datareaders don't have a constructor... or at least not a public one. Therefore, trying to use the &quot;new&quot; keyword on the declaration throws the aforementioned exception.

change this:
Dim objData As New sqlDataReader

to this:
Dim objData As sqlDataReader

:)
paul
penny1.gif
penny1.gif
 
Duh, dummy me. Left that when I changed from using a DataSet to the DataReader... but still got errors, tho not compiler errors.

My error catch gives me this (not sure what it means):
System.InvalidOperationException: Invalid attempt to read when no data is present. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at System.Data.SqlClient.SqlDataReader.get_Item(String name) at ASP.weddingForm_aspx.Page_Load()

My code looks like this now:
Sub Page_Load()
Dim strConn, strSql, orderID, filmType, scanSetup AS String
orderID = Request.Form(&quot;OrderID&quot;)
orderNum.Text = orderID
Dim objData As sqlDataReader
Dim objConn As SqlConnection
Dim objCom As SqlCommand
strConn = &quot;server=Dell2400;database=DP2;uid=dp2user;password=dp2;&quot;
strSql = &quot;SELECT ScanSetup FROM Orders WHERE ID LIKE '&quot; & orderID & &quot;'&quot;
sqlText.Text = strSql
objConn = New SqlConnection(strConn)
objCom = New SqlCommand(strSql, objConn)
Try
objConn.Open()
objData = objCom.ExecuteReader()
scanSetup = objData(&quot;ScanSetup&quot;)
film.Text = scanSetup
objData.Close()
objConn.Close()
Catch e as Exception
ErrorMsg.Text = e.ToString()
End Try
if NOT scanSetup = &quot;&quot; then
Select Case scanSetup
Case &quot;WED LR 120/220 6x6 (SBA)&quot;
filmType = &quot;Wed6x6&quot;
Case &quot;WED LR 120/220 6x7 (SBA)&quot;
filmType = &quot;Wed6x7&quot;
Case Else
ErrorMsg.Text = &quot;There was no film type defined for this order.&quot;
End Select
end if
End Sub
 
I'd try that sql expression on its own first and see if your getting any data back at all. the part of your error message that said:
Invalid attempt to read when no data is present.

would suggest that there aren't any records coming back.

If you can get a set of records, then there's an issue with returning that set and assigning it to whatever object your using.

Thats where I would check first anyway
:)

jack
 
Well... I have it output the sql string to the screen so I can see exactly what it's trying. when I do this, it gives me the one column one record result I'm looking for. Now, I believe it is a string, but I am going to try CStr just to be safe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top