Results 1 to 3 of 3

Thread: Object reference not set..

  1. #1

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Object reference not set..

    hi to everyone...i have this very simple problem that i cant fixed..
    when i select an item in the dropdownlist to be a reference to query in the table it gives me an error: object reference not set to an instance of an object:
    PHP Code:
    <style>
    .
    verdana{
       
    font:8pt verdana;
    }
    </
    style>

    <%@ 
    Page Language="vb" %>
    <%@ 
    import namespace="System.data" %>
    <%@ 
    import namespace="System.data.Sqlclient" %>
    <
    html>
    <
    head>
    </
    head>

    <
    script runat=server>
    sub btnonclick(as object,as eventargs)
    dim cn as new sqlconnection("initial catalog=northwind;integrated security=true;data source=localhost")
    dim dt as new datatable("sample")
    dim da as new Sqldataadapter("select * from region where regionid=" category.selecteditem.text,cn)
    da.fill(dt)
    mygrid.datasource=dt
    mygrid
    .databind()
    end sub
    </script>
    <
    body>

    <
    form runat=server>

    <
    asp:button class=arial text="display table" onclick="btnonclick" runat="server"/>
    <
    p>
    <%
    dim cn as new sqlconnection("initial catalog=northwind;integrated security=true;data source=localhost")
    cn.open()
    dim cm as new sqlcommand("select * from region",cn)
    dim dr as sqldatareader cm.executereader()
    while 
    dr.read()
    category.items.add(dr(0))
    end while%>
    <
    p>
    <
    font face="verdana" size=2>Category:</font> <asp:dropdownlist class="verdana" id="category" runat=server/> 
    <
    p>
    <
    asp:datagrid id="mygrid" class="verdana" backcolor="lightgray" headerstyle-backcolor="#ccccff" runat="server"/>
    </
    form>
    </
    body>
    </
    html
    what's wrong w/ it???
    pls help..

    tanx in advance guys..

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Where is your declaration for the category object?

  3. #3

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    PHP Code:
    <font face="verdana" size=2>Category:</font> <asp:dropdownlist class="verdana" id="category" runat=server/> 
    any ideas???

    thanks in advance..

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