Click here to Skip to main content
15,894,064 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Sir,
I want to developed vote polling application in c# .
with mysql database .but it give error like ADO: Column 'Answer' does not belong to table Table .
plz help me.

code are as follows,
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
 using System.Data.Odbc;
partial class Poll: System.Web.UI.Page
{

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
	    {
			lblPollQuestion.Text = "Answer";
  			DisplayPoll();
        }
    }

    private void DisplayPoll()
    {
        try
        {
             DataSet ds = GetActivePoll();
            // ArrayList listCols = new ArrayList();

            //   Displays the poll
             lblPollQuestion.Text = (ds.Tables[0].Rows[0]["Question"]).ToString();

             int i = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                rdoPollOptionList.Items.Add(dr["Answer"].ToString());
                rdoPollOptionList.Items[i].Value = dr["PK_OptionId"].ToString();
                rdoPollOptionList.SelectedIndex =0;
              //  listCols.Add("Answer");

                i++;
             }
    
        } catch (Exception ex)
        {

	
		 throw ex;
        }
     }
  

       private DataSet GetActivePoll() 
       {
	   try
	   {
       		string  strConnString = (System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"]).ToString();
       		//SqlConnection sqlConn  = new SqlConnection(strConnString);
        
 OdbcConnection MyConnection = new OdbcConnection(strConnString );
    MyConnection.Open();
//SqlClient.SqlConnection sqlConn = new SqlClient.SqlConnection();
//sqlConn.ConnectionString = ("Data Source=C:InetpubwwwrootPollsPollsApp_Data.mdf");
        

        //   Opens the connection
        	//sqlConn.Open();
			OdbcCommand sqlCmd = new OdbcCommand();

        	sqlCmd.CommandText = "{call GetActivePoll}";
        	sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
        	sqlCmd.Connection = MyConnection ;
		//   Gets the dataset from the sp
          	DataSet ds = new DataSet();
          	OdbcDataAdapter da = new OdbcDataAdapter(sqlCmd);

        //  Execute stored procedure
        	da.Fill(ds);

        //   Close connection
        	MyConnection.Close();
			return ds;
		} catch (Exception ex)
        {
	
			throw ex;
        }
      }

    protected void btnVote_Click( object sender ,  System.EventArgs e)
    {
        if (Response.Cookies["Voted"]!= null)
         {

            Response.Cookies["Voted"].Value = "Voted";
            Response.Cookies["Voted"].Expires = DateTime.Now.AddDays(1);

            lblError.Visible = false;

            //   Checks if the user can still vote by using cookie
            RecordVote();
         } else
         {
            lblError.Visible = true;
         }
     }

      private void RecordVote()
      {
         string  strConnString= System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
         // SqlConnection sqlConn  = new SqlConnection(strConnString);  
 OdbcConnection MyConnection = new OdbcConnection(strConnString );
    MyConnection.Open();

//SqlClient.SqlConnection sqlConn = new SqlClient.SqlConnection();
//sqlConn.ConnectionString = "Data Source=Ser
          OdbcCommand sqlCmd = new OdbcCommand();

          sqlCmd.CommandText = "{call IncreamentVotes(?)}";
          sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
          sqlCmd.Connection = MyConnection;

          //  Creation parameters
          OdbcParameter sqlParamQuestion = new OdbcParameter("@i_OptionId",SqlDbType.Int);

          sqlParamQuestion.Value = rdoPollOptionList.SelectedValue;

          sqlCmd.Parameters.Add(sqlParamQuestion);

          //   Execute stored procedure
          sqlCmd.ExecuteNonQuery();

          //  Close connection
          MyConnection.Close();
      }
}
I i use stored procedure
for this u go site..http://www.beansoftware.com/asp.net-tutorials/poll-application.aspx

actully the project in vb i convert it in c# with mysql plz help me more

Thanks & regard.
yes i have a table with coloumn 'Answer'.
u see the link http://www.beansoftware.com/asp.net-tutorials/poll-application.aspx
for table .I convert only it in mysql
THIS IS THE ERROR
Column 'Answer' does not belong to table Table.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Column 'Answer' does not belong to table Table.

Source Error:


Line 54:
Line 55:
Line 56: throw ex;
Line 57: }
Line 58: }

Source File: c:\Inetpub\wwwroot\Polls-CS\Poll.aspx.cs Line: 56

Stack Trace:


[ArgumentException: Column 'Answer' does not belong to table Table.]
Poll.DisplayPoll() in c:\Inetpub\wwwroot\Polls-CS\Poll.aspx.cs:56
Poll.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Polls-CS\Poll.aspx.cs:16
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Posted
Updated 20-Jul-10 19:52pm
v4
Comments
Sandeep Mewara 20-Jul-10 11:20am    
What is your table structure? Is there a column named 'Answer' in it?
TheyCallMeMrJames 20-Jul-10 11:46am    
Would the port not be easier if you were using a .NET provider? Try this: http://dev.mysql.com/downloads/connector/net/5.0.html
Abhinav S 21-Jul-10 0:25am    
Where exactly do you get the error - as in which line?

Apart from the obvious issues with your post ( you didn't tag it ASP.NET, but you're using ASP.NET, you posted a ton of code, which only tells us that you don't know how to structure a project so that it's well written, well designed and maintainable ), what you've told us is that the error says that your table does not contain the column. You've not told us why you think that it shouldn't say that, or told us anything about the DB structure. We're led to believe that you have no idea what you're dong, you're copying random code off the web, and you haven't read or thought about the error message, which is telling you, quite accurately, that your table doesn't have that column. I think it could be more likely ( well, I hope so ), that your design is not so terrible that your table is called 'table' and that your SQL does not name the table, which is the error. However, as you're at least calling stored procs, but don't tell us the code of the procs, which again tells me you have no idea what info is needed to understand the issue, so I doubt you understand the code, we really can't tell you for sure.
 
Share this answer
 
Comments
mudassir 1988 23-Jul-10 6:33am    
Hi when i debug my code than i saw ,at line ,foreach (DataRow dr in ds.Tables[1].Rows).it cant come at data row and cant give exception ,and goto the line display poll and display the poll but without option what i do.
plz help me
ceck your procedure "GetActivePoll", run it directly in SQL
it wont be returning answer column, or col name may be different
 
Share this answer
 
Comments
mudassir 1988 23-Jul-10 6:33am    
Yes u r right my query are disable to select 'Answer' .my query r as follows
delimiter$$

DROP PROCEDURE IF EXISTS `mysql`.`GetActivePoll` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `GetActivePoll`()
BEGIN
SELECT PK_PollId, Question
FROM pol_question
WHERE Active+0 = '1' ;

SELECT PK_OptionId, Answer, Votes FROM polloptions WHERE FK_PollId IN (SELECT PK_PollID FROM pol_question WHERE Active+0 = '1');

END $$


delimiter ;
I think the error accour due to Active how can i correct it
plz help me
Thanks -
mudassir 1988 23-Jul-10 6:34am    
Hi when i debug my code than i saw ,at line ,foreach (DataRow dr in ds.Tables[1].Rows).it cant come at data row and cant give exception ,and goto the line display poll and display the poll but without option what i do.

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