Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to use CommandBehavior.CloseConnection to close the data conection. When I try this method I get the following error:

No value given for one or more required parameters.

 

Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

 

Source Error:

 

Line 21: lstTest.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection)

 

What am I missing with this? I've tried a few things and nothing seems to work. I can go back to the old db.close method, but this seems cleaner and more efficient. Any thoughts?

 

Cheers!

Posted

This should work

 

Dim SqlString As String = "Your string'"

Dim myCommandE As New SqlCommand(SqlString, myConnection)

Dim objDR As SqlDataReader

MyConnection.Open()

objDR=myCommandE.ExecuteReader(system.data.CommandBehavior.CloseConnection)

While objDR.Read()

Posted

I still can't anything to work. Heck I can't even get a connection after fiddling with it all. This is my code:

 

 

<%@ Page Language="vb" Debug="true" %>

<%@Import Namespace="System.Data" %>

<%@Import Namespace="System.Data.OleDb" %>

<script runat="server">

Sub Page_Load(sender as Object, e as EventArgs)

'Create a connection

Const sConnStr as String="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Inetpub\wwwroot\testing net\Citadel.mdb"

Dim objConn as New OleDbConnection(sConnStr)

 

'You must open the connection before populating the DataReader

objConn.Open()

 

'Create a command object for the query

Const sSQL as String = "SELECT [last name] & ', ' & [First name] FROM Employee WHERE ActiveEmp='Yes' ORDER BY [last name] & ', ' & [First name];"

' Const sSQL as String = "SELECT * FROM Employee"

Dim objCmd as New OleDbCommand(sSQL, objConn)

 

'Create/Populate the DataReader

Dim objDataRead as OleDbDataReader

objDataRead = objCmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)

 

lstTest.DataSource = objDataRead

lstTest.DataBind()

 

' objDR = Nothing

' objConn.Close()

objConn = Nothing

End Sub

</script>

<html>

<body>

<form runat="server" ID="Form1">

<asp:listbox id="lstTest" runat="server" Rows="1" DataTextField="Task" />

</form>

</body>

</html>

 

 

I mean that's it and i looks simple enough. But i know I'm not doing something right when I can't connect to a database 100% of the time.

 

Thanks.

Posted

This code works like a champ

 

<%@Import Namespace="System.Data.OleDb" %>

<%@Import Namespace="System.Data" %>

<%@ Page Language="vb" Debug="true" %>

 

<HTML>

<script runat="server">

 

 

 

Sub Page_Load(sender as Object, e as EventArgs)

'Create a connection

Const sConnStr as String="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\testing net\Citadel.mdb"

Dim objConn as New OleDbConnection(sConnStr)

 

'You must open the connection before populating the DataReader

 

 

'Create a command object for the query

Const sSQL as String = "SELECT * FROM Employee WHERE ActiveEmp='Yes' ORDER BY [last name] & ', ' & [First name];"

Dim objCmd as New OleDbCommand(sSQL, objConn)

 

 

 

'Create/Populate the DataReader

Dim objDataRead as OleDbDataReader

'objDataRead = objCmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)

 

objConn.Open()

ListBoxA.DataTextField = "Last Name"

ListBoxA.DataSource = objCmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)

ListBoxA.DataBind()

 

 

objConn.Close()

objConn = Nothing

End Sub

</script>

<body>

<form runat="server" ID="Form1">

<asp:ListBox id="ListBoxA" runat="server">

<asp:ListItem></asp:ListItem>

</asp:ListBox>

 

</form>

</body>

</HTML>

Posted

Thanks for your help on this, I just started looking at .NET yesterday.

 

I actually got the same error as before on this line:

ListBoxA.DataSource = objCmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)

 

"No value given for one or more required parameters. "

 

I don't get it. I have another little test page that is quite simple and does not get this error. Why is that? Do I need to reference something? I think I'm losing this war with .NET.

 

Thanks again.

Posted

I replied to your last post 2 times. I must have been posting to quickly because I dont see them up here.

 

-----------------

 

Try copying my code verbatim and re-create, move and re-reference the Access.mdb file.

 

Also try a simple script just to make sure that IIS is processing the ASP.NET

 

<script language="vb" runat="server">

 

Public Sub Page_Load(ByVal sender As Object, e As EventArgs)

Response.Write("asp.net is parsing correctly.")

End Sub

 

 

</script>

 

 

If the above DOES work and you have re-created, moved, re-referenced the .mdb file, copied my code verbatim and that still WONT work, then you have to learn Java and be a bean coder!

 

Just kidding. There is a .NET fix, ummm - I dont remember the exact line ---

Or re-install the .NET framework and verify it parses .aspx files.

Posted

Ok, thanks for you help on this. It's weird it works right now, but like a light swtich it turns off. I'll play around with your suggestions if it stops working again (as I assume it will here in a bit).

 

Thanks!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...