Results 1 to 11 of 11

Thread: Resolved! Datagrid error "No value given

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    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:
    1. <%@ Import Namespace="System.Data.OleDB" %>
    2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3. <html>
    4. <head>
    5. <title>B-Series</title>
    6. <script runat="server" language="VB">
    7.     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")
    8.     Dim objCmd As System.Data.OleDb.OleDbCommand
    9.     Dim objRdr As System.Data.OleDb.OleDbDataReader
    10. Dim strCmd As String
    11.  
    12.     Sub Page_Load()
    13.         If Not IsPostBack Then
    14.             'MsgBox("yes")
    15.             BindData()
    16.            
    17.         End If
    18.     End Sub
    19.  
    20.     Sub BindData()
    21.         objConn.Open()
    22.         objCmd = New OleDbCommand("SELECT HP_Model, Brocade_Model, FW, Minimum, Recommended, Next_Planned_Release, Notes FROM status ORDER BY FW, HP_Model", objConn)
    23.         [b]'ERRORS HERE [color=red]objRdr = objCmd.ExecuteReader()[/color][/b][color=red][/color]
    24.         BseriesGrid.DataSource = objRdr
    25.         BseriesGrid.DataBind()
    26.         objRdr.Close()
    27.         objConn.Close()
    28.     End Sub
    29. </script>
    30. </head>
    31.  
    32. <body>
    33.  
    34.  
    35. <form id="Form1" runat="server">
    36.   <table align="center" border="0" width="100%">
    37.        <tr>
    38.                    <td align="center" style="height: 541px">
    39.                  <h1>Firmware Matrix</h1>                                                                                            
    40.  <asp:DataGrid ID="BseriesGrid" runat="server" Caption="B-Series" AutoGenerateColumns="false" BorderColor="red"  BorderStyle="solid" BorderWidth="2" AllowPaging="true" DataKeyField="FW">
    41.  <Columns>
    42. <asp:BoundColumn DataField="HP_Model" HeaderText="HP_Model" />
    43. <asp:BoundColumn DataField="Brocade_Model" HeaderText="Brocade_Model" />
    44.   <asp:BoundColumn DataField="FW" HeaderText="FW" />
    45.       <asp:BoundColumn DataField="Minimum" HeaderText="Minimum" />
    46. <asp:BoundColumn DataField="Recommended" HeaderText="Recommended" />
    47. <asp:BoundColumn DataField="Next_Planned_Release" HeaderText="Next_Planned_Release" />
    48. <asp:BoundColumn DataField="Notes" HeaderText="Notes" />
    49.  </Columns>
    50.    </asp:DataGrid>
    51.                                                                                    
    52.   </td>
    53.          </tr>
    54.       </table>
    55.   </form>
    56.                                                                            
    57.                                                                      
    58.                                                    
    59. </body>
    60.  
    61. </html>
    Last edited by Troy Mac; Aug 30th, 2006 at 03:06 PM. Reason: Resovled
    TMacPherson
    MIS Systems Engineer
    [email protected]


  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Datagrid error "No value given"

    Try this
    VB Code:
    1. Sub BindData()
    2.         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")
    3.         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)
    4.         Dim dt As New DataTable
    5.  
    6.         objConn.Open()
    7.         objDa.Fill(dt)
    8.         BseriesGrid.DataSource = dt
    9.         BseriesGrid.DataBind()
    10.         objRdr.Close()
    11.         objConn.Close()
    12. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    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.
    TMacPherson
    MIS Systems Engineer
    [email protected]


  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Datagrid error "No value given"

    it is probably looking for a Recordset name, so try this, (from top of my head)
    VB Code:
    1. objDa.Fill(dt,"[i]any_random_name_related_to_the_table[/i]")
    Show Appreciation. Rate Posts.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    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?
    TMacPherson
    MIS Systems Engineer
    [email protected]


  6. #6
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    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.
    TMacPherson
    MIS Systems Engineer
    [email protected]


  8. #8
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Datagrid error "No value given"

    all right, i think that the Sub DataBind should look something like this:
    VB Code:
    1. Sub BindData()
    2.  
    3.   objCmd = New OleDbCommand("[i]query_here[/i]", objConn)
    4.   objConn.Open()
    5.   objRdr = objCmd.ExecuteReader()
    6.   BseriesGrid.DataSource = objRdr
    7.   BseriesGrid.DataBind()
    8.   objConn.Close()
    9.  
    10. 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.
    Show Appreciation. Rate Posts.

  9. #9
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Datagrid error "No value given"

    Did you make sure the table and column names are all correctly cased?

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    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
    TMacPherson
    MIS Systems Engineer
    [email protected]


  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    North East America
    Posts
    463

    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)
    TMacPherson
    MIS Systems Engineer
    [email protected]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width