Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have three drop-down lists printing information into a label when an item is selected, all using identical code, however only one succeeds in printing into its corresponding label. I cant see where the code for the other two is going wrong. The error being returned is issue near '=' .

C#
protected void venInfoDDL_SelectedIndexChanged1(object sender, EventArgs e)
       {
           //Creating a select statement that searches for record that matchs VenueID from Value property.
           string venInfoSelectSql;
           venInfoSelectSql = "SELECT * FROM Venue";
           venInfoSelectSql += "WHERE VenueID = '" + venInfoDDL.SelectedItem.Value + "'";

           //defining the ADO.NET objects.
           SqlConnection conB1 = new SqlConnection(adminCon);
           SqlCommand cmdB1 = new SqlCommand(venInfoSelectSql, conB1);
           SqlDataReader readerB1;

           //Opening database and reading information.
           try
           {
               conB1.Open();
               readerB1 = cmdB1.ExecuteReader();
               readerB1.Read();

               //building a string with the record information and displaying in label.
               StringBuilder venInfoSB = new StringBuilder();
               venInfoSB.Append("<b>");
               venInfoSB.Append(readerB1["UserName"]);
               venInfoSB.Append("</b><br/>");
               venInfoSB.Append("VenueID:");
               venInfoSB.Append(readerB1["VenueID"]);
               venInfoSB.Append("<br>");
               venInfoSB.Append("Manager:");
               venInfoSB.Append(readerB1["VenueManager"]);
               venInfoSB.Append("<br/>");
               venInfoSB.Append("Email:");
               venInfoSB.Append(readerB1["VenueEmail"]);
               venInfoSB.Append("<br/>");
               venInfoSB.Append("Phone:");
               venInfoSB.Append(readerB1["VenueTelephoneNumber"]);
               venInfoSB.Append("<br/>");
               venInfoLabel.Text = venInfoSB.ToString();

           }
           catch (Exception err)
           {
               venInfoLabel.Text = "Error getting Venue";
               venInfoLabel.Text += err.Message;
           }
           finally
           {
               conB1.Close();
           }

       }

protected void artInfoDDL_SelectedIndexChanged1(object sender, EventArgs e)
        {
            //Creating Select statement that searches for a record that matches ArtistID from Value property.
            string artInfoSelectSql;
            artInfoSelectSql = "SELECT * FROM Artist";
            artInfoSelectSql += "WHERE ArtistID = '" + artInfoDDL.SelectedItem.Value + "'";

            //defining the ADO.NET objects.
            SqlConnection conC1 = new SqlConnection(adminCon);
            SqlCommand cmdC1 = new SqlCommand(artInfoSelectSql, conC1);
            SqlDataReader readerC1;

            //Opening database & reading information.
            try
            {
                conC1.Open();
                readerC1 = cmdC1.ExecuteReader();
                readerC1.Read();

                //building a string with the record information and diplaying in label.
                StringBuilder artInfoSB = new StringBuilder();
                artInfoSB.Append("<b>");
                artInfoSB.Append(readerC1["UserName"]);
                artInfoSB.Append("</b><br/>");
                artInfoSB.Append("ArtistID:");
                artInfoSB.Append(readerC1["ArtistID"]);
                artInfoSB.Append("<br/>");
                artInfoSB.Append("Contact:");
                artInfoSB.Append(readerC1["ArtistContactName"]);
                artInfoSB.Append("<br/>");
                artInfoSB.Append("Email:");
                artInfoSB.Append(readerC1["ArtistEmail"]);
                artInfoSB.Append("<br/>");
                artInfoSB.Append("Phone:");
                artInfoSB.Append(readerC1["ArtistTelNo"]);
                artInfoSB.Append("<br/>");
                artInfoLabel.Text = artInfoSB.ToString();


            }
            catch (Exception err)
            {
                artInfoLabel.Text = "Error getting Artist.";
                artInfoLabel.Text += err.Message;

            }
            finally
            {
                conC1.Close();
            }
        }
Posted
Updated 22-Apr-14 23:47pm
v2

SQL
string venInfoSelectSql;
venInfoSelectSql = "SELECT * FROM Venue";
venInfoSelectSql += "WHERE VenueID = '" + venInfoDDL.SelectedItem.Value + "'";

results in query: SELECT * FROM VenueWHERE VenueID =....
you miss the space between Venue and WHERE
 
Share this answer
 
Comments
DamithSL 23-Apr-14 5:52am    
but that is common for both statements. then how only one fail!
Coder-Ferg 23-Apr-14 6:05am    
Sorry, both of the above were the methods that were not working. Here is the one that works .

protected void perInfoDDL_SelectedIndexChanged1(object sender, EventArgs e)
{
//Creating Select statement that searches for record that matches PersonalID from Value property.
string perInfoSelectSql;
perInfoSelectSql = "SELECT * FROM Personal"; // maybe "SELECT PersonalUsername, Surname, FirstName, PersonalEmail, TelephoneNo FROM Personal"; "SELECT * FROM Personal";
perInfoSelectSql += " WHERE PersonalID= '" + perInfoDDL.SelectedItem.Value + "'";

//Defining the ADO.NET objects
SqlConnection conA1 = new SqlConnection(adminCon);
SqlCommand cmdA1 = new SqlCommand(perInfoSelectSql, conA1);
SqlDataReader readerA1;

//Opening database & reading information
try
{
conA1.Open();
readerA1 = cmdA1.ExecuteReader();
readerA1.Read();

//building a string with the record information and displaying in label.

StringBuilder perInfoSB = new StringBuilder(); //use System.Text with it
perInfoSB.Append("");
perInfoSB.Append("Username:");
perInfoSB.Append(readerA1["UserName"]);
perInfoSB.Append("
<br/>");
perInfoSB.Append("<br/>");
perInfoSB.Append("PersonalID:");
perInfoSB.Append(readerA1["PersonalID"]);
perInfoSB.Append("<br/>");
perInfoSB.Append("Name:");
perInfoSB.Append(readerA1["Surname"]);
perInfoSB.Append(", ");
perInfoSB.Append(readerA1["FirstName"]);
perInfoSB.Append("<br/>");
perInfoSB.Append("Email:");
perInfoSB.Append(readerA1["PersonalEmail"]);
perInfoSB.Append("<br/>");
perInfoSB.Append("Phone:");
perInfoSB.Append(readerA1["TelephoneNo"]);
perInfoSB.Append("<br/>");
perInfoLabel.Text = perInfoSB.ToString();

readerA1.Close();
}
catch (Exception err)
{
perInfoLabel.Text = "Error reading Personal.";
perInfoLabel.Text += err.Message;
}
finally
{
conA1.Close();
}
}
Herman<T>.Instance 23-Apr-14 6:59am    
is your problem solved now?
Try This

C#
  StringBuilder artInfoSB = new StringBuilder();
While(readerC1.Read())
 {
  //building a string with the record information and diplaying in label.
  artInfoSB.Append("<b>");
  artInfoSB.Append(readerC1["UserName"]);
  artInfoSB.Append("</b><br/>");
  artInfoSB.Append("ArtistID:");
  artInfoSB.Append(readerC1["ArtistID"]);
  artInfoSB.Append("<br/>");
  artInfoSB.Append("Contact:");
  artInfoSB.Append(readerC1["ArtistContactName"]);
  artInfoSB.Append("<br/>");
  artInfoSB.Append("Email:");
  artInfoSB.Append(readerC1["ArtistEmail"]);
  artInfoSB.Append("<br/>");
  artInfoSB.Append("Phone:");
  artInfoSB.Append(readerC1["ArtistTelNo"]);
  artInfoSB.Append("<br/>");
  artInfoLabel.Text = artInfoSB.ToString();
 }
 
Share this answer
 
v2
Comments
Coder-Ferg 23-Apr-14 6:02am    
Thank you, i tried that to, but for some reason when i run it in web browser it is still returning this error .

Incorrect syntax near '='.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900