Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Drop down list not populated

Posted on 2004-10-21
8
Medium Priority
?
376 Views
Last Modified: 2008-02-01
Thd drop down list on this form is not populated. It should.
I'm suspecting my connecting string is not correct.
Also when I submit the form , I'm getting this error on LINE 41:
Please help

=================
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 39:     Dim I as Integer
Line 40:     DBConn = New OleDbConnection("Provider=sqloledb;server=localhost;Initial Catalog=test;DataSource=local;User Id=pojo;Password=CANCER6768;")
Line 41:     DBCommand = New OleDbDataAdapter("Select Distinct CustomerEmail from Customers Where GroupName = '" & ddlGroupName.SelectedItem.Text & "'", DBConn)
Line 42:     DBCommand.Fill(DSPageData,"Emails")
Line 43:     TheMailMessage.From = txtFrom.Text
 ==============================================================


<%@ Import Namespace="System.Data.OLEDB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Page Language="vb" Debug="true" CodeBehind="index.aspx.vb" AutoEventWireup="false" Inherits="test.index" %>
<HTML>
      <HEAD>
            <TITLE>Email Blast</TITLE>
            <script runat="server">
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    If Not IsPostBack Then
        Dim DBConn as OleDbConnection
        Dim DBCommand As OleDbDataAdapter
        Dim DSPageData as New DataSet
        DBConn = New OleDbConnection("Provider=sqloledb;server=localhost;Initial Catalog=testDB;DataSource=local;User Id=MOPLK;Password=OLFACTORY;")
           
           
        DBCommand = New OleDbDataAdapter ("Select Distinct GroupName from Customers Order By GroupName", DBConn)
        DBCommand.Fill(DSPageData, "Groups")
        ddlGroupName.DataSource = DSPageData.Tables("Groups").DefaultView
        ddlGroupName.DataBind()
       

    End If
End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
    Dim DBConn as OleDbConnection
    Dim DBCommand As OleDbDataAdapter
    Dim DSPageData as New DataSet
  Dim ThemailMessage As System.Web.Mail.MailMessage
    Dim TheMailConnection  
 
 
'System.Web.Mail.MailMessage
'Dim messageText As String =3D ""
'Dim strHTML as String =3D ""
   
   
   
    Dim I as Integer
    DBConn = New OleDbConnection("Provider=sqloledb;server=localhost;Initial Catalog=testDB;DataSource=local;User Id=MOPLK;Password=OLFACTORY;")
    DBCommand = New OleDbDataAdapter("Select Distinct CustomerEmail from Customers Where GroupName = '" & ddlGroupName.SelectedItem.Text & "'", DBConn)
    DBCommand.Fill(DSPageData,"Emails")
    TheMailMessage.From = txtFrom.Text
    TheMailMessage.Subject = txtSubject.Text
    TheMailMessage.Body = txtMessage.Text
    For I = 0 to DSPageData.Tables("Emails"). Rows.Count - 1
        TheMailMessage.To = DSPageData.Tables("Emails"). Rows(0).Item("CustomerEmail")
        TheMailConnection.Send(TheMailMessage)
    Next
    if DSPageData.Tables("Emails").Rows.Count = 1 then
        lblMessage.Text = "Your message has been sent to 1" _
            & " person. You can now send another email blast."
    Else
        lblMessage.Text = "Your message has been sent to " _
            & DSPageData.Tables("Emails").Rows.Count _
            & " people. You can now send another email blast."
    End If
End Sub
            </script>
      </HEAD>
      <BODY BACKGROUND="./lp.gif" TEXT="darkslateblue" LINK="darkred" VLINK="darkred" ALINK="red"
            LEFTMARGIN="140">
            <form runat="server">
                  <asp:Label id="lblTitle" Font-Size="25pt" Font-Name="Tahoma" Text="Email Blast" runat="server" />
                  <BR>
                  <IMG SRC="/test/images/line.gif"> <Font Face="Tahoma">
                        <BR>
                        <BR>
                        <asp:Label id="lblMessage" Font-Size="12pt" Font-Name="Tahoma" Font-Bold="True" runat="server"
                              Text="Select the group that you wish to send the email to &#13;&#10;        then enter your message." />
                        <BR>
                        <BR>
                        <asp:dropdownlist id="ddlGroupName" runat="server" DataTextField="GroupName"></asp:dropdownlist>
                        <BR>
                        <IMG SRC="/test/images/line.gif"> <Font Face="Tahoma">
                              <BR>
                              <Table>
                                    <TR>
                                          <TD>
                                                <B>From:</B>
                                          </TD>
                                          <TD>
                                                <asp:TextBox id="txtFrom" Columns="40" MaxLength="100" runat="server" />
                                                <asp:RequiredFieldValidator id="rfvFrom" ControlToValidate="txtFrom" Display="Dynamic" Font-Name="Verdana" Font-Size="10pt"
                                                      runat="server">
    <BR>The From field is Required!
</asp:RequiredFieldValidator>
                                          </TD>
                                    </TR>
                                    <TR>
                                          <TD>
                                                <B>Subject:</B>
                                          </TD>
                                          <TD>
                                                <asp:TextBox id="txtSubject" Columns="40" MaxLength="100" runat="server" />
                                                <asp:RequiredFieldValidator id="rfvSubject" ControlToValidate="txtSubject" Display="Dynamic" Font-Name="Verdana"
                                                      Font-Size="10pt" runat="server">
    <BR>The Subject field is Required!
</asp:RequiredFieldValidator>
                                          </TD>
                                    </TR>
                                    <TR>
                                          <TD VAlign="top">
                                                <B>Message:</B>
                                          </TD>
                                          <TD>
                                                <asp:TextBox id="txtMessage" Columns="40" Rows="5" runat="server" TextMode="MultiLine" />
                                                <asp:RequiredFieldValidator id="rfvMessage" ControlToValidate="txtMessage" Display="Dynamic" Font-Name="Verdana"
                                                      Font-Size="10pt" runat="server">
    <BR>The Message field is Required!
</asp:RequiredFieldValidator>
                                          </TD>
                                    </TR>
                              </Table>
                              <BR>
                              <asp:button id="butOK" text="  OK  " Type="Submit" OnClick="SubmitBtn_Click" runat="server" />
                        </Font>
            </form>
            </FONT>
      </BODY>
</HTML>
0
Comment
Question by:iyiola
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 8

Expert Comment

by:thrill_house
ID: 12371560
Try changing:
 DBCommand = New OleDbDataAdapter("Select Distinct CustomerEmail from Customers Where GroupName = '" & ddlGroupName.SelectedItem.Text & "'", DBConn)

to

 DBCommand = New OleDbDataAdapter("Select Distinct CustomerEmail from Customers Where GroupName = '" & ddlGroupName.SelectedValue & "'", DBConn)

I've never used ddl.SelectedItem.Text, so I don't know if this will work or not, but it might be looking at an empty item (which may not exist), which is why it is throwing an error.
-Thrill
0
 

Author Comment

by:iyiola
ID: 12371941
Hi Thrill, Thanks but one more thing. The drop down is not populating. I don't knw why this is so.
There is record in the database.
Any suggestion?
0
 
LVL 4

Expert Comment

by:vinhthuy_nguyen
ID: 12372368
Hi,

did you try to run your query directly in SQL Server?
how about the DataValueField in your ddl, I don't see it in the property ?
Just my thinking.Just forget it if you went through already
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:daffodils
ID: 12372549
Set the DataTextField and DataValueField

"DataTextField" to the column name you want to display on the combo box.
"DataValueField" to the column name you want to retrieve as value.
0
 

Author Comment

by:iyiola
ID: 12373044
Hi daffodis and vinhthuy unguyen
I did already, still not working.

<asp:dropdownlist id="ddlGroupName" runat="server" DataTextField="GroupName"></asp:dropdownlist>
0
 
LVL 8

Expert Comment

by:daffodils
ID: 12373911
It should be as..
<asp:dropdownlist id="ddlGroupName" runat="server" DataTextField="GroupName" DataValueField="GroupName"></asp:dropdownlist>

Try commenting out line 41.
Then do a simple Response.Write for "ddlGroupName.SelectedItem.Text" in the SubmitBtn_Click sub.

Does it print the Group Name??
0
 

Author Comment

by:iyiola
ID: 12374332
No Response.write did not print the Group Name. I'm sure there is data in teh database but not sure I'm connected to it.  I'm not getting any errors again, but the  drop down list is not populating. It's suppose to when get to our home page (this page)

0
 
LVL 8

Accepted Solution

by:
daffodils earned 500 total points
ID: 12374633
Okay, so the DropDownList is not getting populated in the first place !

Have you tested the connection .. as to if you are getting connected to the database in the first place?
Looks like you are not sure...
>>I'm sure there is data in teh database but not sure I'm connected to it.

Create a new test page. Put a DataGrid into it and using your connection string, databind it to the Customers Table.
Does it connect to the Database and show all records on the DataGrid??
If not, check your Connection String.

Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    If Not IsPostBack Then
        Dim DBConn as OleDbConnection
        Dim DBAdpater As OleDbDataAdapter
        Dim DSTest as New DataSet

        DBAdapter = New OleDbDataAdapter ("Select * from Customers", DBConn)
        DBAdpater.Fill(DSTest, "Customers")
        dgTest.DataSource = DSTest.Tables("Customers").DefaultView
        dgTest.DataBind()
  End If
End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question