Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ERROR [HY000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.48-community]Incorrect integer value: '' for column 'i_OptionId' at row 1

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.Data.Odbc.OdbcException: ERROR [HY000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.48-community]Incorrect integer value: '' for column 'i_OptionId' at row 1

Source Error:


Line 136:
Line 137: // Execute stored procedure
Line 138: sqlCmd.ExecuteNonQuery();
Line 139:
Line 140: // Close connection

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

Stack Trace:


[OdbcException (0x80131937): ERROR [HY000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.48-community]Incorrect integer value: '' for column 'i_OptionId' at row 1]
System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) +1155538
System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod) +1147
System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader) +61
System.Data.Odbc.OdbcCommand.ExecuteNonQuery() +92
Poll.RecordVote() in c:\Inetpub\wwwroot\Polls-CS\Poll.aspx.cs:138
Poll.btnVote_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Polls-CS\Poll.aspx.cs:108
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
code is

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.Text = dr[0].ToString(); //gives correct value
//rdoPollOptionList.Text = (ds.Tables[0].Columns[0]).ToString(); // gives "PNR"
//rdoPollOptionList.Text =(dr["Answer"]).ToString(); //Gives error, why?
//rdoPollOptionList.Items[i].Value = dr["PK_OptionId"].ToString();

//foreach ( Column in dtTable.Columns)




rdoPollOptionList.Items.Add(dr["Answer"].ToString());
rdoPollOptionList.Items[i].Value = dr["PK_OptionId"].ToString();
rdoPollOptionList.SelectedIndex =0;

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 = 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 = 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();
}
}
Posted
Updated 21-Jul-10 6:52am
v2

1 solution

You are passing in '' for column i_OptionId.
However, your code expects an integer value - hence probably your error.
 
Share this answer
 

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