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

eliminate error msg

Status
Not open for further replies.

dawtes

Programmer
Jun 23, 2005
31
US
Hi all,
Can somone advise me what i need to do to eliminate this error msg.
thanks


Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'CommandBehavior' is not declared.





<%@ import namespace="System.Data.OleDb"%>
<html>
<head>
<title>connecting to a Database using vb</title></head>
<script runat="server" language="VB">
dim i As Integer
dim filename as string
dim sb as System.Text.StringBuilder
dim cn as OleDbConnection
dim cmd as OleDbCommand
dim dr as OleDbDataReader

Protected WithEvents Button1 as Button

Sub Button1_Click(ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click


cn = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;"& _
"Data Source=c:\Inetpub\ & _
"Dorknozzle.mdb")
filename="products.csv"
cmd = New OleDbCommand("Select * from Employees", cn)
cmd.Connection.open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
sb= New System.Text.StringBuilder

'for field name
For i=0 to dr.FieldCount-1
If i < (dr.FieldCount-1) then
sb.Append(Chr(34)&dr.GetName(i)&Chr(34)&",")
Else
sb.Append(Chr(34)&dr.GetName(i)&Chr(34)& VbCrLf)
End If
next


'for field value
While dr.Read()
For i=0 to dr.FieldCount-1
If i < (dr.FieldCount-1) then
sb.Append(Chr(34)&dr.GetValue(i).ToString & Chr(34)&",")
Else
sb.Append(Chr(34)&dr.GetValue(i).ToString & Chr(34)& VbCrLf)
End if
Next

End while
dr.close()
cn.Close()
Response.ContentType ="Application/x-msexcel"
Response.AddHeader("content-disposition","attachment;filename="""& filename &"""")
Response.Write(sb.ToString)
Response.End()

End Sub
</script>
 
You'll need to remove "CommandBehavior.CloseConnection" when you open your datareader (you shouldn be attempting to close it here anyway as you are reading from it later).



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Try adding this
<%@ import namespace="System.Data"%>
this is the namespace that the CommandBehavior Enumeration lives in.
ca8msm,
I believe this will not close the connection until the associated reader is closed.

Marty
 
cappmgr - you are of course right. What I should have said was that it wasn't needed as the user has called the close method of both the datareader and the connection after reading the results.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top