|
-
Aug 30th, 2006, 10:02 AM
#1
Thread Starter
Hyperactive Member
Resolved! Datagrid error "No value given
My datagrid will not populate. I continue to get this error:
System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147217904
Message="No value given for one or more required parameters."
Source="Microsoft JET Database Engine"
Here is my code, if someone could look at it and tell me where I am going wrong that would be great.
VB Code:
<%@ Import Namespace="System.Data.OleDB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>B-Series</title>
<script runat="server" language="VB">
Dim objConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Documents and Settings\TMACPHERSON\My Documents\Visual Studio 2005\Projects\CodFish\BrocadeFirmwareStatus.mdb")
Dim objCmd As System.Data.OleDb.OleDbCommand
Dim objRdr As System.Data.OleDb.OleDbDataReader
Dim strCmd As String
Sub Page_Load()
If Not IsPostBack Then
'MsgBox("yes")
BindData()
End If
End Sub
Sub BindData()
objConn.Open()
objCmd = New OleDbCommand("SELECT HP_Model, Brocade_Model, FW, Minimum, Recommended, Next_Planned_Release, Notes FROM status ORDER BY FW, HP_Model", objConn)
[b]'ERRORS HERE [color=red]objRdr = objCmd.ExecuteReader()[/color][/b][color=red][/color]
BseriesGrid.DataSource = objRdr
BseriesGrid.DataBind()
objRdr.Close()
objConn.Close()
End Sub
</script>
</head>
<body>
<form id="Form1" runat="server">
<table align="center" border="0" width="100%">
<tr>
<td align="center" style="height: 541px">
<h1>Firmware Matrix</h1>
<asp:DataGrid ID="BseriesGrid" runat="server" Caption="B-Series" AutoGenerateColumns="false" BorderColor="red" BorderStyle="solid" BorderWidth="2" AllowPaging="true" DataKeyField="FW">
<Columns>
<asp:BoundColumn DataField="HP_Model" HeaderText="HP_Model" />
<asp:BoundColumn DataField="Brocade_Model" HeaderText="Brocade_Model" />
<asp:BoundColumn DataField="FW" HeaderText="FW" />
<asp:BoundColumn DataField="Minimum" HeaderText="Minimum" />
<asp:BoundColumn DataField="Recommended" HeaderText="Recommended" />
<asp:BoundColumn DataField="Next_Planned_Release" HeaderText="Next_Planned_Release" />
<asp:BoundColumn DataField="Notes" HeaderText="Notes" />
</Columns>
</asp:DataGrid>
</td>
</tr>
</table>
</form>
</body>
</html>
Last edited by Troy Mac; Aug 30th, 2006 at 03:06 PM.
Reason: Resovled
-
Aug 30th, 2006, 12:08 PM
#2
Re: Datagrid error "No value given"
Try this
VB Code:
Sub BindData()
Dim objConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Documents and Settings\TMACPHERSON\My Documents\Visual Studio 2005\Projects\CodFish\BrocadeFirmwareStatus.mdb")
Dim objDa As New System.Data.OleDb.OleDbDataAdapter("SELECT HP_Model, Brocade_Model, FW, Minimum, Recommended, Next_Planned_Release, Notes FROM status ORDER BY FW, HP_Model", objConn)
Dim dt As New DataTable
objConn.Open()
objDa.Fill(dt)
BseriesGrid.DataSource = dt
BseriesGrid.DataBind()
objRdr.Close()
objConn.Close()
End Sub
-
Aug 30th, 2006, 12:31 PM
#3
Thread Starter
Hyperactive Member
Re: Datagrid error "No value given"
Thanks Wild Bill, but I get the same error No value given for one or more required parameter only I get it on the objDa.Fill(dt). I have double checked my database table many times for typos I even went to the the trouble of copying and pasting each field name to make sure they are right.
The strange thing is I grabed my code directly from an asp.net book and when I do the example in the book it will grab the data from the database (different database) and the code works. all I did was change the path to the database and the select statement to match my database. For some reason it will not fill the OleDataReader or Adapter, it is looking for some kind of parameter. Any other ideas???
thanks again.
-
Aug 30th, 2006, 01:10 PM
#4
Re: Datagrid error "No value given"
it is probably looking for a Recordset name, so try this, (from top of my head)
VB Code:
objDa.Fill(dt,"[i]any_random_name_related_to_the_table[/i]")
-
Aug 30th, 2006, 01:45 PM
#5
Thread Starter
Hyperactive Member
Re: Datagrid error "No value given"
Thanks Harsh but its a no go. I get Object is not an ADODB.RecordSet or an ADODB.Record.
Parameter name: adodb this is crazy... This should be a simple task but I guess not Any ideas on how to do it with the code from my first post?
-
Aug 30th, 2006, 01:47 PM
#6
Re: Datagrid error "No value given"
*edit* The table name and column names might be case sensative, check that out. *edit*
Could it be a security issue? Have you tried adding a username/password to your connection string?
Last edited by wild_bill; Aug 30th, 2006 at 01:55 PM.
-
Aug 30th, 2006, 01:55 PM
#7
Thread Starter
Hyperactive Member
Re: Datagrid error "No value given"
Nope not security, it is an access database with no security set up at all and the DB is in the path of the dev web site. I could get the data adding a accessdatasource though the GUI of VS2005 but I could not set edit and stuff so I would rather do this through code and not rely on visual studio to set the datasource and binds for the grids.
-
Aug 30th, 2006, 02:34 PM
#8
Re: Datagrid error "No value given"
all right, i think that the Sub DataBind should look something like this:
VB Code:
Sub BindData()
objCmd = New OleDbCommand("[i]query_here[/i]", objConn)
objConn.Open()
objRdr = objCmd.ExecuteReader()
BseriesGrid.DataSource = objRdr
BseriesGrid.DataBind()
objConn.Close()
End Sub
Also, set the AllowCustomPaging property of <asp: DataGrid> to True. Not necessary, since i tried with a small mdb file, and the error asked me to do it.
and do check if you set the KeyField "FW" in your table.
BTW, it would be better if you work using DataTable because you will work in disconnected environment and it will make your job much easier than Reader thingy.
hope it helps you.
-
Aug 30th, 2006, 02:40 PM
#9
Re: Datagrid error "No value given"
Did you make sure the table and column names are all correctly cased?
-
Aug 30th, 2006, 02:53 PM
#10
Thread Starter
Hyperactive Member
Re: Datagrid error "No value given"
Ok Harsh, I will try this and see if I can get it to work.
I just created and accessdatasource and bound the grid through the GUI and it works fine so I know the database is accessable. I am using this Awesome book Build your own ASP.NET Website using C# & VB.Net by Zak Ruvalcaba but because of this project at work I have had to skip to the middle of the book and I am a newbie to .NET Thanks for your help Harsh and Bill.
-Troy
-
Aug 30th, 2006, 03:04 PM
#11
Thread Starter
Hyperactive Member
Re: Datagrid error "No value given"
Think I got it. I took all the autogenerated parameters from the accessdatasource and put them in my sub routine then deleted the datasource one this I think made the difference is the way the select statement was formated. notice the brackets. anyway it looks like it is working now I just need to figure out how to edit the rows LOL!
"SELECT [HP Model] AS HP_Model, [Brocade Model] AS Brocade_Model, [FW], [Minimum], [Recommended], [Next_Planned_Release], [Notes] FROM [status] ORDER BY [FW], [HP Model]", objConn)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|