Saturday, March 31, 2012

System.InvalidCastException

Hope someone can help. I am trying to get a submit button working and
getting this error now System.InvalidCastException: Object must implement
IConvertible. This is showing up on the ExecuteNonQuery line. Below is the
code that I have in my Page_load. I also have no idea of what code I would
use in the Submit_Click event to get the insert to work. Any help would be
appreciated
OleDbConnection conn = new
OleDbConnection("Provider=OraOLEDB.Oracle.1;Persist Security
Info=False;"+"User ID=conference;Password=conf00;Data
Source=ntdrp001.world;");
OleDbCommand command = new OleDbCommand("CONF-REQUEST_INSERT", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("DropDownList1", OleDbType.VarChar).Value =
DropDownList1;
command.Parameters.Add("DropDownList2", OleDbType.VarChar).Value =
DropDownList2;
command.Parameters.Add("txtEStartDate", OleDbType.Date).Value =
txtEStartDate;
command.Parameters.Add("txtEEndDate", OleDbType.Date).Value = txtEEndDate;
command.Parameters.Add("txtEStartTime", OleDbType.Numeric).Value =
txtEStartTime;
command.Parameters.Add("txtEEndTime", OleDbType.Numeric).Value =
txtEEndTime;
command.Parameters.Add("txtEventName", OleDbType.VarChar).Value =
txtEventName;
command.Parameters.Add("txtEventSize", OleDbType.Numeric).Value =
txtEventSize;
command.Parameters.Add("txtSStartDate", OleDbType.Date).Value =
txtSStartDate;
command.Parameters.Add("txtSStartTime", OleDbType.Numeric).Value =
txtSStartTime;
command.Parameters.Add("txtEventDescription", OleDbType.VarChar).Value =
txtEventDescription;
command.Parameters.Add("txtSpecialRequirements", OleDbType.VarChar).Value =
txtSpecialRequirements;
conn.Open();
int rows = command.ExecuteNonQuery();
conn.Close();Hi, Brian,
The reason is that you directly use the web control objects for the value as
signments. You have to use their properties. like:
command.Parameters.Add("DropDownList1", OleDbType.VarChar).Value = DropDownL
ist1.SelectedItem.Value;
command.Parameters.Add("txtEStartDate", OleDbType.Date).Value = txtEStartDat
e.Text;
Bin Song, MCP

0 comments:

Post a Comment