本文介绍了C#编程中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


先生,
我想用c#开发投票表决应用程序.
与mysql数据库.但是它会给出类似ADO的错误:列"Answer"不属于表Table.
请帮我.

代码如下,

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();
      }
}

我使用存储过程
为此,请访问网站.http://www.beansoftware.com/asp.net-tutorials/poll-application.aspx

在vb中实际执行项目,我使用mysql plz在c#中将其转换为我,

谢谢&注意.
是的,我有一张桌子,用大写的答案".
您会看到链接http://www.beansoftware.com/asp.net-tutorials/poll-application.aspx
对于表.我仅在mysql中转换它
这是错误
列"Answer"不属于表Table.

说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息.

异常详细信息:System.ArgumentException:列"Answer"不属于表Table.

源错误:


第54行:
第55行:
第56行:throw ex;
第57行:}
第58行:}

源文件:c:\ Inetpub \ wwwroot \ Polls-CS \ Poll.aspx.cs行:56

堆栈跟踪:


[ArgumentException:列"Answer"不属于表Table.]
c:\ Inetpub \ wwwroot \ Polls-CS \ Poll.aspx.cs中的Poll.DisplayPoll():56
c:\ Inetpub \ wwwroot \ Polls-CS \ Poll.aspx.cs中的Poll.Page_Load(对象发件人,EventArgs e):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

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

推荐答案



这篇关于C#编程中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 02:40