473,385 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Casting a TextBox Properly?

I have a DataGrid that is passing information to a stored procedure properly
but the parameters aren't being casted properly. I was woundering if anyone
can tell me how I should properly cast the following:

(TextBox)UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
string strUserPrefix=UserPrefix.Text;

I keep getting the following error and I don't know why because I have
declared the UserPrefix as a textbox using "protected
System.Web.UI.Webcontrols.TextBox UserPrefix" as well as casting it in its
referance.

Here is the error message I get:

Specified cast is not valid.
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.InvalidCastException: Specified cast is not valid.

Source Error:
Line 84: int EditIDupdate=(int)clubdg.DataKeys[(int)e.Item.ItemIndex];
Line 85:
Line 86: UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
Line 87: string strUserPrefix=UserPrefix.Text;
Line 88: UserFName=(TextBox)e.Item.Cells[0].Controls[1];
Source File: c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs Line: 86

Stack Trace:
[InvalidCastException: Specified cast is not valid.]
Sonar3.Secured.UserGrid.Update_Click(Object sender,
DataGridCommandEventArgs e) in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs :86

System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs
e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

The Codebehind is as follows:

protected System.Web.UI.WebControls.TextBox UserPrefix;
protected System.Web.UI.WebControls.TextBox UserFName;
protected System.Web.UI.WebControls.TextBox UserLName;
protected System.Web.UI.WebControls.TextBox UserEmail;
protected System.Web.UI.WebControls.TextBox UserPassword;
protected System.Web.UI.WebControls.TextBox UserStreetNumber;
protected System.Web.UI.WebControls.TextBox UserAddress;
protected System.Web.UI.WebControls.TextBox UserCity;
protected System.Web.UI.WebControls.TextBox UserProvince;
protected System.Web.UI.WebControls.TextBox UserPostal;
protected System.Web.UI.WebControls.TextBox UserPhone;
protected System.Web.UI.WebControls.TextBox UserFax;
protected System.Web.UI.WebControls.TextBox UserMobile;
protected System.Web.UI.WebControls.TextBox UserNote;
protected System.Web.UI.WebControls.TextBox _Date;
protected System.Web.UI.WebControls.CheckBox show;
protected System.Web.UI.WebControls.CheckBox Bookings;
protected System.Web.UI.WebControls.CheckBox General;
protected System.Web.UI.WebControls.CheckBox GuestList;
protected System.Web.UI.WebControls.CheckBox BarInfo;
public void Update_Click(Object sender, DataGridCommandEventArgs e)
{
int EditIDupdate=(int)clubdg.DataKeys[(int)e.Item.ItemIndex];

(TextBox)UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
string strUserPrefix=UserPrefix.Text;
UserFName=(TextBox)e.Item.Cells[0].Controls[1];
string strUserFName=UserFName.Text;
UserLName=(TextBox)e.Item.Cells[0].Controls[2];
string strUserLName=UserLName.Text;

UserEmail=(TextBox)e.Item.Cells[1].Controls[0];
string strUserEmail=UserEmail.Text;
UserPassword=(TextBox)e.Item.Cells[1].Controls[1];
string strUserPassword=UserPassword.Text;

UserStreetNumber=(TextBox)e.Item.Cells[2].Controls[0];
string strUserStreetNumber=UserStreetNumber.Text;
UserAddress=(TextBox)e.Item.Cells[2].Controls[1];
string strUserAddress=UserAddress.Text;
UserCity=(TextBox)e.Item.Cells[2].Controls[2];
string strUserCity=UserCity.Text;
UserProvince=(TextBox)e.Item.Cells[2].Controls[3];
string strUserProvince=UserProvince.Text;
UserPostal=(TextBox)e.Item.Cells[2].Controls[4];
string strUserPostal=UserPostal.Text;

UserPhone=(TextBox)e.Item.Cells[3].Controls[0];
string strUserPhone=UserPhone.Text;
UserFax=(TextBox)e.Item.Cells[3].Controls[1];
string strUserFax=UserFax.Text;
UserMobile=(TextBox)e.Item.Cells[3].Controls[2];
string strUserMobile=UserMobile.Text;

show=(CheckBox)e.Item.Cells[1].Controls[2];
string strShow=show.Text;
Bookings=(CheckBox)e.Item.Cells[1].Controls[3];
string strBookings=Bookings.Text;
General=(CheckBox)e.Item.Cells[1].Controls[4];
string strGeneral=General.Text;
GuestList=(CheckBox)e.Item.Cells[1].Controls[5];
string strGuestList=GuestList.Text;
BarInfo=(CheckBox)e.Item.Cells[1].Controls[6];
string strBarInfo=BarInfo.Text;

clubconn=new SqlConnection(strclubconn);
clubconn.Open();
clubcmd=new SqlCommand(Globals.UserUpdate_SP,clubconn);
clubcmd.CommandType=CommandType.StoredProcedure;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPrefix_PARM,SqlD bType.Char,5));
clubcmd.Parameters[Globals.User_tbl_UserPrefix_PARM].Value=strUserPrefix;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFName_PARM,SqlDb Type.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserFName_PARM].Value=strUserFName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserLName_PARM,SqlDb Type.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserLName_PARM].Value=strUserLName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserEmail_PARM,SqlDb Type.Char,255));
clubcmd.Parameters[Globals.User_tbl_UserEmail_PARM].Value=strUserEmail;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPassword_PARM,Sq lDbType.Char,16));
clubcmd.Parameters[Globals.User_tbl_UserPassword_PARM].Value=strUserPassword;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserStreetNumber_PAR M,SqlDbType.Int,4));
clubcmd.Parameters[Globals.User_tbl_UserStreetNumber_PARM].Value=strUserStreetNumber;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserAddress_PARM,Sql DbType.Char,200));
clubcmd.Parameters[Globals.User_tbl_UserAddress_PARM].Value=strUserAddress;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserCity_PARM,SqlDbT ype.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserCity_PARM].Value=strUserCity;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserProvince_PARM,Sq lDbType.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserProvince_PARM].Value=strUserProvince;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPostal_PARM,SqlD bType.Char,10));
clubcmd.Parameters[Globals.User_tbl_UserPostal_PARM].Value=strUserPostal;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPhone_PARM,SqlDb Type.Int,9));
clubcmd.Parameters[Globals.User_tbl_UserPhone_PARM].Value=strUserPhone;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFax_PARM,SqlDbTy pe.Char,9));
clubcmd.Parameters[Globals.User_tbl_UserFax_PARM].Value=strUserFax;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserMobile_PARM,SqlD bType.Char,9));
clubcmd.Parameters[Globals.User_tbl_UserMobile_PARM].Value=strUserMobile;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_show_PARM,SqlDbType. Bit,1));
clubcmd.Parameters[Globals.User_tbl_show_PARM].Value=strShow;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_Bookings_PARM,SqlDbT ype.Bit,1));
clubcmd.Parameters[Globals.User_tbl_Bookings_PARM].Value=strBookings;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_General_PARM,SqlDbTy pe.Bit,1));
clubcmd.Parameters[Globals.User_tbl_General_PARM].Value=strGeneral;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_GuestList_PARM,SqlDb Type.Bit,1));
clubcmd.Parameters[Globals.User_tbl_GuestList_PARM].Value=strGuestList;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_BarInfo_PARM,SqlDbTy pe.Bit,1));
clubcmd.Parameters[Globals.User_tbl_BarInfo_PARM].Value=strBarInfo;

clubcmd.ExecuteNonQuery();
clubconn.Close();
clubdg.EditItemIndex=-1;
BindData();
}
Nov 19 '05 #1
7 2082
Sam:

It is quite possible then that the cell contains more controls than
just the TextBox, and the control you are referencing is not really a
TextBox.

A more robust solution is to give the control an ID and obtain a
reference using FindControl:
http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 15 Mar 2005 07:51:01 -0800, "I am Sam"
<Ia****@discussions.microsoft.com> wrote:
I have a DataGrid that is passing information to a stored procedure properly
but the parameters aren't being casted properly. I was woundering if anyone
can tell me how I should properly cast the following:

(TextBox)UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
string strUserPrefix=UserPrefix.Text;

I keep getting the following error and I don't know why because I have
declared the UserPrefix as a textbox using "protected
System.Web.UI.Webcontrols.TextBox UserPrefix" as well as casting it in its
referance.

Here is the error message I get:

Specified cast is not valid.
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.InvalidCastException: Specified cast is not valid.

Source Error:
Line 84: int EditIDupdate=(int)clubdg.DataKeys[(int)e.Item.ItemIndex];
Line 85:
Line 86: UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
Line 87: string strUserPrefix=UserPrefix.Text;
Line 88: UserFName=(TextBox)e.Item.Cells[0].Controls[1];
Source File: c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs Line: 86

Stack Trace:
[InvalidCastException: Specified cast is not valid.]
Sonar3.Secured.UserGrid.Update_Click(Object sender,
DataGridCommandEventArgs e) in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.c s:86

System.Web.UI.WebControls.DataGrid.OnUpdateComman d(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs
e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

The Codebehind is as follows:

protected System.Web.UI.WebControls.TextBox UserPrefix;
protected System.Web.UI.WebControls.TextBox UserFName;
protected System.Web.UI.WebControls.TextBox UserLName;
protected System.Web.UI.WebControls.TextBox UserEmail;
protected System.Web.UI.WebControls.TextBox UserPassword;
protected System.Web.UI.WebControls.TextBox UserStreetNumber;
protected System.Web.UI.WebControls.TextBox UserAddress;
protected System.Web.UI.WebControls.TextBox UserCity;
protected System.Web.UI.WebControls.TextBox UserProvince;
protected System.Web.UI.WebControls.TextBox UserPostal;
protected System.Web.UI.WebControls.TextBox UserPhone;
protected System.Web.UI.WebControls.TextBox UserFax;
protected System.Web.UI.WebControls.TextBox UserMobile;
protected System.Web.UI.WebControls.TextBox UserNote;
protected System.Web.UI.WebControls.TextBox _Date;
protected System.Web.UI.WebControls.CheckBox show;
protected System.Web.UI.WebControls.CheckBox Bookings;
protected System.Web.UI.WebControls.CheckBox General;
protected System.Web.UI.WebControls.CheckBox GuestList;
protected System.Web.UI.WebControls.CheckBox BarInfo;
public void Update_Click(Object sender, DataGridCommandEventArgs e)
{
int EditIDupdate=(int)clubdg.DataKeys[(int)e.Item.ItemIndex];

(TextBox)UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
string strUserPrefix=UserPrefix.Text;
UserFName=(TextBox)e.Item.Cells[0].Controls[1];
string strUserFName=UserFName.Text;
UserLName=(TextBox)e.Item.Cells[0].Controls[2];
string strUserLName=UserLName.Text;

UserEmail=(TextBox)e.Item.Cells[1].Controls[0];
string strUserEmail=UserEmail.Text;
UserPassword=(TextBox)e.Item.Cells[1].Controls[1];
string strUserPassword=UserPassword.Text;

UserStreetNumber=(TextBox)e.Item.Cells[2].Controls[0];
string strUserStreetNumber=UserStreetNumber.Text;
UserAddress=(TextBox)e.Item.Cells[2].Controls[1];
string strUserAddress=UserAddress.Text;
UserCity=(TextBox)e.Item.Cells[2].Controls[2];
string strUserCity=UserCity.Text;
UserProvince=(TextBox)e.Item.Cells[2].Controls[3];
string strUserProvince=UserProvince.Text;
UserPostal=(TextBox)e.Item.Cells[2].Controls[4];
string strUserPostal=UserPostal.Text;

UserPhone=(TextBox)e.Item.Cells[3].Controls[0];
string strUserPhone=UserPhone.Text;
UserFax=(TextBox)e.Item.Cells[3].Controls[1];
string strUserFax=UserFax.Text;
UserMobile=(TextBox)e.Item.Cells[3].Controls[2];
string strUserMobile=UserMobile.Text;

show=(CheckBox)e.Item.Cells[1].Controls[2];
string strShow=show.Text;
Bookings=(CheckBox)e.Item.Cells[1].Controls[3];
string strBookings=Bookings.Text;
General=(CheckBox)e.Item.Cells[1].Controls[4];
string strGeneral=General.Text;
GuestList=(CheckBox)e.Item.Cells[1].Controls[5];
string strGuestList=GuestList.Text;
BarInfo=(CheckBox)e.Item.Cells[1].Controls[6];
string strBarInfo=BarInfo.Text;

clubconn=new SqlConnection(strclubconn);
clubconn.Open();
clubcmd=new SqlCommand(Globals.UserUpdate_SP,clubconn);
clubcmd.CommandType=CommandType.StoredProcedure;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPrefix_PARM,Sql DbType.Char,5));
clubcmd.Parameters[Globals.User_tbl_UserPrefix_PARM].Value=strUserPrefix;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFName_PARM,SqlD bType.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserFName_PARM].Value=strUserFName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserLName_PARM,SqlD bType.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserLName_PARM].Value=strUserLName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserEmail_PARM,SqlD bType.Char,255));
clubcmd.Parameters[Globals.User_tbl_UserEmail_PARM].Value=strUserEmail;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPassword_PARM,S qlDbType.Char,16));
clubcmd.Parameters[Globals.User_tbl_UserPassword_PARM].Value=strUserPassword;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserStreetNumber_PA RM,SqlDbType.Int,4));
clubcmd.Parameters[Globals.User_tbl_UserStreetNumber_PARM].Value=strUserStreetNumber;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserAddress_PARM,Sq lDbType.Char,200));
clubcmd.Parameters[Globals.User_tbl_UserAddress_PARM].Value=strUserAddress;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserCity_PARM,SqlDb Type.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserCity_PARM].Value=strUserCity;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserProvince_PARM,S qlDbType.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserProvince_PARM].Value=strUserProvince;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPostal_PARM,Sql DbType.Char,10));
clubcmd.Parameters[Globals.User_tbl_UserPostal_PARM].Value=strUserPostal;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPhone_PARM,SqlD bType.Int,9));
clubcmd.Parameters[Globals.User_tbl_UserPhone_PARM].Value=strUserPhone;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFax_PARM,SqlDbT ype.Char,9));
clubcmd.Parameters[Globals.User_tbl_UserFax_PARM].Value=strUserFax;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserMobile_PARM,Sql DbType.Char,9));
clubcmd.Parameters[Globals.User_tbl_UserMobile_PARM].Value=strUserMobile;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_show_PARM,SqlDbType .Bit,1));
clubcmd.Parameters[Globals.User_tbl_show_PARM].Value=strShow;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_Bookings_PARM,SqlDb Type.Bit,1));
clubcmd.Parameters[Globals.User_tbl_Bookings_PARM].Value=strBookings;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_General_PARM,SqlDbT ype.Bit,1));
clubcmd.Parameters[Globals.User_tbl_General_PARM].Value=strGeneral;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_GuestList_PARM,SqlD bType.Bit,1));
clubcmd.Parameters[Globals.User_tbl_GuestList_PARM].Value=strGuestList;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_BarInfo_PARM,SqlDbT ype.Bit,1));
clubcmd.Parameters[Globals.User_tbl_BarInfo_PARM].Value=strBarInfo;

clubcmd.ExecuteNonQuery();
clubconn.Close();
clubdg.EditItemIndex=-1;
BindData();
}


Nov 19 '05 #2
Scott's absolutely right...and to expand on this, spaces and newlines are
converted to LiteralControls....this makes the entire ordinal reference very
brittle, if you add a space between two controls, a new LiteralControl will
be created and your indexs all increment by 1....hence use the
FindControl("controlId") approach for robustness..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:gj********************************@4ax.com...
Sam:

It is quite possible then that the cell contains more controls than
just the TextBox, and the control you are referencing is not really a
TextBox.

A more robust solution is to give the control an ID and obtain a
reference using FindControl:
http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 15 Mar 2005 07:51:01 -0800, "I am Sam"
<Ia****@discussions.microsoft.com> wrote:
I have a DataGrid that is passing information to a stored procedure properlybut the parameters aren't being casted properly. I was woundering if anyonecan tell me how I should properly cast the following:

(TextBox)UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
string strUserPrefix=UserPrefix.Text;

I keep getting the following error and I don't know why because I have
declared the UserPrefix as a textbox using "protected
System.Web.UI.Webcontrols.TextBox UserPrefix" as well as casting it in itsreferance.

Here is the error message I get:

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

Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 84: int EditIDupdate=(int)clubdg.DataKeys[(int)e.Item.ItemIndex];
Line 85:
Line 86: UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
Line 87: string strUserPrefix=UserPrefix.Text;
Line 88: UserFName=(TextBox)e.Item.Cells[0].Controls[1];
Source File: c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs Line: 86
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
Sonar3.Secured.UserGrid.Update_Click(Object sender,
DataGridCommandEventArgs e) in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.c s:86


System.Web.UI.WebControls.DataGrid.OnUpdateComman d(DataGridCommandEventArgs

e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgse)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)


System.Web.UI.WebControls.LinkButton.System.Web.U I.IPostBackEventHandler.Ra

isePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

The Codebehind is as follows:

protected System.Web.UI.WebControls.TextBox UserPrefix;
protected System.Web.UI.WebControls.TextBox UserFName;
protected System.Web.UI.WebControls.TextBox UserLName;
protected System.Web.UI.WebControls.TextBox UserEmail;
protected System.Web.UI.WebControls.TextBox UserPassword;
protected System.Web.UI.WebControls.TextBox UserStreetNumber;
protected System.Web.UI.WebControls.TextBox UserAddress;
protected System.Web.UI.WebControls.TextBox UserCity;
protected System.Web.UI.WebControls.TextBox UserProvince;
protected System.Web.UI.WebControls.TextBox UserPostal;
protected System.Web.UI.WebControls.TextBox UserPhone;
protected System.Web.UI.WebControls.TextBox UserFax;
protected System.Web.UI.WebControls.TextBox UserMobile;
protected System.Web.UI.WebControls.TextBox UserNote;
protected System.Web.UI.WebControls.TextBox _Date;
protected System.Web.UI.WebControls.CheckBox show;
protected System.Web.UI.WebControls.CheckBox Bookings;
protected System.Web.UI.WebControls.CheckBox General;
protected System.Web.UI.WebControls.CheckBox GuestList;
protected System.Web.UI.WebControls.CheckBox BarInfo;
public void Update_Click(Object sender, DataGridCommandEventArgs e)
{
int EditIDupdate=(int)clubdg.DataKeys[(int)e.Item.ItemIndex];

(TextBox)UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
string strUserPrefix=UserPrefix.Text;
UserFName=(TextBox)e.Item.Cells[0].Controls[1];
string strUserFName=UserFName.Text;
UserLName=(TextBox)e.Item.Cells[0].Controls[2];
string strUserLName=UserLName.Text;

UserEmail=(TextBox)e.Item.Cells[1].Controls[0];
string strUserEmail=UserEmail.Text;
UserPassword=(TextBox)e.Item.Cells[1].Controls[1];
string strUserPassword=UserPassword.Text;

UserStreetNumber=(TextBox)e.Item.Cells[2].Controls[0];
string strUserStreetNumber=UserStreetNumber.Text;
UserAddress=(TextBox)e.Item.Cells[2].Controls[1];
string strUserAddress=UserAddress.Text;
UserCity=(TextBox)e.Item.Cells[2].Controls[2];
string strUserCity=UserCity.Text;
UserProvince=(TextBox)e.Item.Cells[2].Controls[3];
string strUserProvince=UserProvince.Text;
UserPostal=(TextBox)e.Item.Cells[2].Controls[4];
string strUserPostal=UserPostal.Text;

UserPhone=(TextBox)e.Item.Cells[3].Controls[0];
string strUserPhone=UserPhone.Text;
UserFax=(TextBox)e.Item.Cells[3].Controls[1];
string strUserFax=UserFax.Text;
UserMobile=(TextBox)e.Item.Cells[3].Controls[2];
string strUserMobile=UserMobile.Text;

show=(CheckBox)e.Item.Cells[1].Controls[2];
string strShow=show.Text;
Bookings=(CheckBox)e.Item.Cells[1].Controls[3];
string strBookings=Bookings.Text;
General=(CheckBox)e.Item.Cells[1].Controls[4];
string strGeneral=General.Text;
GuestList=(CheckBox)e.Item.Cells[1].Controls[5];
string strGuestList=GuestList.Text;
BarInfo=(CheckBox)e.Item.Cells[1].Controls[6];
string strBarInfo=BarInfo.Text;

clubconn=new SqlConnection(strclubconn);
clubconn.Open();
clubcmd=new SqlCommand(Globals.UserUpdate_SP,clubconn);
clubcmd.CommandType=CommandType.StoredProcedure;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPrefix_PARM,Sql DbType.Char,5));
clubcmd.Parameters[Globals.User_tbl_UserPrefix_PARM].Value=strUserPrefix;
clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFName_PARM,SqlD bType.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserFName_PARM].Value=strUserFName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserLName_PARM,SqlD bType.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserLName_PARM].Value=strUserLName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserEmail_PARM,SqlD bType.Char,255));
clubcmd.Parameters[Globals.User_tbl_UserEmail_PARM].Value=strUserEmail;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPassword_PARM,S qlDbType.Char,16));
clubcmd.Parameters[Globals.User_tbl_UserPassword_PARM].Value=strUserPassword
;
clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserStreetNumber_PA RM,SqlDbType.Int,4));
clubcmd.Parameters[Globals.User_tbl_UserStreetNumber_PARM].Value=strUserStre
etNumber;
clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserAddress_PARM,Sq lDbType.Char,200));
clubcmd.Parameters[Globals.User_tbl_UserAddress_PARM].Value=strUserAddress;
clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserCity_PARM,SqlDb Type.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserCity_PARM].Value=strUserCity;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserProvince_PARM,S qlDbType.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserProvince_PARM].Value=strUserProvince
;
clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPostal_PARM,Sql DbType.Char,10));
clubcmd.Parameters[Globals.User_tbl_UserPostal_PARM].Value=strUserPostal;
clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPhone_PARM,SqlD bType.Int,9));
clubcmd.Parameters[Globals.User_tbl_UserPhone_PARM].Value=strUserPhone;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFax_PARM,SqlDbT ype.Char,9));
clubcmd.Parameters[Globals.User_tbl_UserFax_PARM].Value=strUserFax;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserMobile_PARM,Sql DbType.Char,9));
clubcmd.Parameters[Globals.User_tbl_UserMobile_PARM].Value=strUserMobile;
clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_show_PARM,SqlDbType .Bit,1));
clubcmd.Parameters[Globals.User_tbl_show_PARM].Value=strShow;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_Bookings_PARM,SqlDb Type.Bit,1));
clubcmd.Parameters[Globals.User_tbl_Bookings_PARM].Value=strBookings;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_General_PARM,SqlDbT ype.Bit,1));
clubcmd.Parameters[Globals.User_tbl_General_PARM].Value=strGeneral;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_GuestList_PARM,SqlD bType.Bit,1));
clubcmd.Parameters[Globals.User_tbl_GuestList_PARM].Value=strGuestList;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_BarInfo_PARM,SqlDbT ype.Bit,1));
clubcmd.Parameters[Globals.User_tbl_BarInfo_PARM].Value=strBarInfo;

clubcmd.ExecuteNonQuery();
clubconn.Close();
clubdg.EditItemIndex=-1;
BindData();
}

Nov 19 '05 #3
Hi Scott Allen,

Thank you. You were correct. Now, I am finding extra space in the textbox
fields when I debug. As well I keep getting the following error message:

Input string was not in a correct format.
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.FormatException: Input string was not in a correct
format.

Source Error:
Line
194: clubcmd.Parameters[Globals.User_tbl_BarInfo_PARM].Value=strBarInfo;
Line 195:
Line 196: clubcmd.ExecuteNonQuery();
Line 197: clubconn.Close();
Line 198: clubdg.EditItemIndex=-1;
Source File: c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs Line: 196

Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Sonar3.Secured.UserGrid.Update_Click(Object sender,
DataGridCommandEventArgs e) in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs :196

System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs
e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
I don't know which Textbox the error is refering to. Any Ideas?
"Scott Allen" wrote:
Sam:

It is quite possible then that the cell contains more controls than
just the TextBox, and the control you are referencing is not really a
TextBox.

A more robust solution is to give the control an ID and obtain a
reference using FindControl:
http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 15 Mar 2005 07:51:01 -0800, "I am Sam"
<Ia****@discussions.microsoft.com> wrote:
I have a DataGrid that is passing information to a stored procedure properly
but the parameters aren't being casted properly. I was woundering if anyone
can tell me how I should properly cast the following:

(TextBox)UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
string strUserPrefix=UserPrefix.Text;

I keep getting the following error and I don't know why because I have
declared the UserPrefix as a textbox using "protected
System.Web.UI.Webcontrols.TextBox UserPrefix" as well as casting it in its
referance.

Here is the error message I get:

Specified cast is not valid.
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.InvalidCastException: Specified cast is not valid.

Source Error:
Line 84: int EditIDupdate=(int)clubdg.DataKeys[(int)e.Item.ItemIndex];
Line 85:
Line 86: UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
Line 87: string strUserPrefix=UserPrefix.Text;
Line 88: UserFName=(TextBox)e.Item.Cells[0].Controls[1];
Source File: c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.cs Line: 86

Stack Trace:
[InvalidCastException: Specified cast is not valid.]
Sonar3.Secured.UserGrid.Update_Click(Object sender,
DataGridCommandEventArgs e) in
c:\inetpub\wwwroot\sonar3\secured\usergrid.aspx.c s:86

System.Web.UI.WebControls.DataGrid.OnUpdateComman d(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs
e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

The Codebehind is as follows:

protected System.Web.UI.WebControls.TextBox UserPrefix;
protected System.Web.UI.WebControls.TextBox UserFName;
protected System.Web.UI.WebControls.TextBox UserLName;
protected System.Web.UI.WebControls.TextBox UserEmail;
protected System.Web.UI.WebControls.TextBox UserPassword;
protected System.Web.UI.WebControls.TextBox UserStreetNumber;
protected System.Web.UI.WebControls.TextBox UserAddress;
protected System.Web.UI.WebControls.TextBox UserCity;
protected System.Web.UI.WebControls.TextBox UserProvince;
protected System.Web.UI.WebControls.TextBox UserPostal;
protected System.Web.UI.WebControls.TextBox UserPhone;
protected System.Web.UI.WebControls.TextBox UserFax;
protected System.Web.UI.WebControls.TextBox UserMobile;
protected System.Web.UI.WebControls.TextBox UserNote;
protected System.Web.UI.WebControls.TextBox _Date;
protected System.Web.UI.WebControls.CheckBox show;
protected System.Web.UI.WebControls.CheckBox Bookings;
protected System.Web.UI.WebControls.CheckBox General;
protected System.Web.UI.WebControls.CheckBox GuestList;
protected System.Web.UI.WebControls.CheckBox BarInfo;
public void Update_Click(Object sender, DataGridCommandEventArgs e)
{
int EditIDupdate=(int)clubdg.DataKeys[(int)e.Item.ItemIndex];

(TextBox)UserPrefix=(TextBox)e.Item.Cells[0].Controls[0];
string strUserPrefix=UserPrefix.Text;
UserFName=(TextBox)e.Item.Cells[0].Controls[1];
string strUserFName=UserFName.Text;
UserLName=(TextBox)e.Item.Cells[0].Controls[2];
string strUserLName=UserLName.Text;

UserEmail=(TextBox)e.Item.Cells[1].Controls[0];
string strUserEmail=UserEmail.Text;
UserPassword=(TextBox)e.Item.Cells[1].Controls[1];
string strUserPassword=UserPassword.Text;

UserStreetNumber=(TextBox)e.Item.Cells[2].Controls[0];
string strUserStreetNumber=UserStreetNumber.Text;
UserAddress=(TextBox)e.Item.Cells[2].Controls[1];
string strUserAddress=UserAddress.Text;
UserCity=(TextBox)e.Item.Cells[2].Controls[2];
string strUserCity=UserCity.Text;
UserProvince=(TextBox)e.Item.Cells[2].Controls[3];
string strUserProvince=UserProvince.Text;
UserPostal=(TextBox)e.Item.Cells[2].Controls[4];
string strUserPostal=UserPostal.Text;

UserPhone=(TextBox)e.Item.Cells[3].Controls[0];
string strUserPhone=UserPhone.Text;
UserFax=(TextBox)e.Item.Cells[3].Controls[1];
string strUserFax=UserFax.Text;
UserMobile=(TextBox)e.Item.Cells[3].Controls[2];
string strUserMobile=UserMobile.Text;

show=(CheckBox)e.Item.Cells[1].Controls[2];
string strShow=show.Text;
Bookings=(CheckBox)e.Item.Cells[1].Controls[3];
string strBookings=Bookings.Text;
General=(CheckBox)e.Item.Cells[1].Controls[4];
string strGeneral=General.Text;
GuestList=(CheckBox)e.Item.Cells[1].Controls[5];
string strGuestList=GuestList.Text;
BarInfo=(CheckBox)e.Item.Cells[1].Controls[6];
string strBarInfo=BarInfo.Text;

clubconn=new SqlConnection(strclubconn);
clubconn.Open();
clubcmd=new SqlCommand(Globals.UserUpdate_SP,clubconn);
clubcmd.CommandType=CommandType.StoredProcedure;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPrefix_PARM,Sql DbType.Char,5));
clubcmd.Parameters[Globals.User_tbl_UserPrefix_PARM].Value=strUserPrefix;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFName_PARM,SqlD bType.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserFName_PARM].Value=strUserFName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserLName_PARM,SqlD bType.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserLName_PARM].Value=strUserLName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserEmail_PARM,SqlD bType.Char,255));
clubcmd.Parameters[Globals.User_tbl_UserEmail_PARM].Value=strUserEmail;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPassword_PARM,S qlDbType.Char,16));
clubcmd.Parameters[Globals.User_tbl_UserPassword_PARM].Value=strUserPassword;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserStreetNumber_PA RM,SqlDbType.Int,4));
clubcmd.Parameters[Globals.User_tbl_UserStreetNumber_PARM].Value=strUserStreetNumber;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserAddress_PARM,Sq lDbType.Char,200));
clubcmd.Parameters[Globals.User_tbl_UserAddress_PARM].Value=strUserAddress;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserCity_PARM,SqlDb Type.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserCity_PARM].Value=strUserCity;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserProvince_PARM,S qlDbType.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserProvince_PARM].Value=strUserProvince;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPostal_PARM,Sql DbType.Char,10));
clubcmd.Parameters[Globals.User_tbl_UserPostal_PARM].Value=strUserPostal;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPhone_PARM,SqlD bType.Int,9));
clubcmd.Parameters[Globals.User_tbl_UserPhone_PARM].Value=strUserPhone;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFax_PARM,SqlDbT ype.Char,9));
clubcmd.Parameters[Globals.User_tbl_UserFax_PARM].Value=strUserFax;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserMobile_PARM,Sql DbType.Char,9));
clubcmd.Parameters[Globals.User_tbl_UserMobile_PARM].Value=strUserMobile;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_show_PARM,SqlDbType .Bit,1));
clubcmd.Parameters[Globals.User_tbl_show_PARM].Value=strShow;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_Bookings_PARM,SqlDb Type.Bit,1));
clubcmd.Parameters[Globals.User_tbl_Bookings_PARM].Value=strBookings;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_General_PARM,SqlDbT ype.Bit,1));
clubcmd.Parameters[Globals.User_tbl_General_PARM].Value=strGeneral;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_GuestList_PARM,SqlD bType.Bit,1));
clubcmd.Parameters[Globals.User_tbl_GuestList_PARM].Value=strGuestList;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_BarInfo_PARM,SqlDbT ype.Bit,1));
clubcmd.Parameters[Globals.User_tbl_BarInfo_PARM].Value=strBarInfo;

clubcmd.ExecuteNonQuery();
clubconn.Close();
clubdg.EditItemIndex=-1;
BindData();
}


Nov 19 '05 #4
On Tue, 15 Mar 2005 10:09:02 -0800, "I am Sam"
<Ia****@discussions.microsoft.com> wrote:
Hi Scott Allen,

Thank you. You were correct. Now, I am finding extra space in the textbox
fields when I debug. As well I keep getting the following error message:

Input string was not in a correct format.
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.FormatException: Input string was not in a correct
format.


What is the type of the parameter the query expects?

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #5
I don't know which field is causing the error exception the message comes up
when I set the the command as follows:

clubcmd.ExecuteNonQuery();
Which is correct. I tried turning off some variables and parameters but
some fields are required so I get a seperate exception error.

Below are the fields:
UserPrefix=((TextBox)e.Item.Cells[0].FindControl("UserPrefix"));
string strUserPrefix=UserPrefix.Text;
strUserPrefix.Trim();
UserFName=(TextBox)e.Item.Cells[0].FindControl("UserFName");
string strUserFName=UserFName.Text;
strUserFName.Trim();
UserLName=(TextBox)e.Item.Cells[0].FindControl("UserLName");
string strUserLName=UserLName.Text;
strUserLName.Trim();

UserEmail=(TextBox)e.Item.Cells[1].FindControl("UserEmail");
string strUserEmail=UserEmail.Text;
strUserEmail.Trim();
UserPassword=(TextBox)e.Item.Cells[1].FindControl("UserPassword");
string strUserPassword=UserPassword.Text;
strUserPassword.Trim();
UserAccess=(DropDownList)e.Item.Cells[1].FindControl("AccessID");
string strAccessID=UserAccess.SelectedValue;

UserStreetNumber=(TextBox)e.Item.Cells[2].FindControl("UserStreetNumber");
string strUserStreetNumber=UserStreetNumber.Text;
strUserStreetNumber.Trim();
UserAddress=(TextBox)e.Item.Cells[2].FindControl("UserAddress");
string strUserAddress=UserAddress.Text;
strUserAddress.Trim();
UserCity=(TextBox)e.Item.Cells[2].FindControl("UserCity");
string strUserCity=UserCity.Text;
strUserCity.Trim();
UserProvince=(TextBox)e.Item.Cells[2].FindControl("UserProvince");
string strUserProvince=UserProvince.Text;
strUserProvince.Trim();
UserPostal=(TextBox)e.Item.Cells[2].FindControl("UserPostal");
string strUserPostal=UserPostal.Text;
strUserPostal.Trim();

UserPhone=(TextBox)e.Item.Cells[3].FindControl("UserPhone");
string strUserPhone=UserPhone.Text;
UserFax=(TextBox)e.Item.Cells[3].FindControl("UserFax");
string strUserFax=UserFax.Text;
UserMobile=(TextBox)e.Item.Cells[3].FindControl("UserMobile");;
string strUserMobile=UserMobile.Text;

show=(CheckBox)e.Item.Cells[1].FindControl("show");
bool strShow=show.Checked;
Bookings=(CheckBox)e.Item.Cells[1].FindControl("Bookings");
bool strBookings=Bookings.Checked;
General=(CheckBox)e.Item.Cells[1].FindControl("General");
bool strGeneral=General.Checked;
GuestList=(CheckBox)e.Item.Cells[1].FindControl("GuestList");
bool strGuestList=GuestList.Checked;
BarInfo=(CheckBox)e.Item.Cells[1].FindControl("BarInfo");
bool strBarInfo=BarInfo.Checked;
then I set the connection as follows:

clubconn=new SqlConnection(strclubconn);
clubconn.Open();
clubcmd=new SqlCommand(Globals.UserUpdate_SP,clubconn);
clubcmd.CommandType=CommandType.StoredProcedure;
And then the Parameters:

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserID_PARM,SqlDbTyp e.Int,4));
clubcmd.Parameters[Globals.User_tbl_UserID_PARM].Value=EditIDupdate;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPrefix_PARM,SqlD bType.Char,5));
clubcmd.Parameters[Globals.User_tbl_UserPrefix_PARM].Value=strUserPrefix;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFName_PARM,SqlDb Type.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserFName_PARM].Value=strUserFName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserLName_PARM,SqlDb Type.Char,150));
clubcmd.Parameters[Globals.User_tbl_UserLName_PARM].Value=strUserLName;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserEmail_PARM,SqlDb Type.Char,255));
clubcmd.Parameters[Globals.User_tbl_UserEmail_PARM].Value=strUserEmail;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPassword_PARM,Sq lDbType.Char,16));
clubcmd.Parameters[Globals.User_tbl_UserPassword_PARM].Value=strUserPassword;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_AccessID_PARM,SqlDbT ype.Char,5));
clubcmd.Parameters[Globals.User_tbl_AccessID_PARM].Value=strAccessID;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserStreetNumber_PAR M,SqlDbType.Int,4));
clubcmd.Parameters[Globals.User_tbl_UserStreetNumber_PARM].Value=strUserStreetNumber;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserAddress_PARM,Sql DbType.Char,200));
clubcmd.Parameters[Globals.User_tbl_UserAddress_PARM].Value=strUserAddress;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserCity_PARM,SqlDbT ype.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserCity_PARM].Value=strUserCity;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserProvince_PARM,Sq lDbType.Char,20));
clubcmd.Parameters[Globals.User_tbl_UserProvince_PARM].Value=strUserProvince;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPostal_PARM,SqlD bType.Char,10));
clubcmd.Parameters[Globals.User_tbl_UserPostal_PARM].Value=strUserPostal;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserPhone_PARM,SqlDb Type.Int,12));
clubcmd.Parameters[Globals.User_tbl_UserPhone_PARM].Value=strUserPhone;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserFax_PARM,SqlDbTy pe.Char,12));
clubcmd.Parameters[Globals.User_tbl_UserFax_PARM].Value=strUserFax;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_UserMobile_PARM,SqlD bType.Char,12));
clubcmd.Parameters[Globals.User_tbl_UserMobile_PARM].Value=strUserMobile;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_show_PARM,SqlDbType. Bit,1));
clubcmd.Parameters[Globals.User_tbl_show_PARM].Value=strShow;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_Bookings_PARM,SqlDbT ype.Bit,1));
clubcmd.Parameters[Globals.User_tbl_Bookings_PARM].Value=strBookings;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_General_PARM,SqlDbTy pe.Bit,1));
clubcmd.Parameters[Globals.User_tbl_General_PARM].Value=strGeneral;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_GuestList_PARM,SqlDb Type.Bit,1));
clubcmd.Parameters[Globals.User_tbl_GuestList_PARM].Value=strGuestList;

clubcmd.Parameters.Add(new
SqlParameter(Globals.User_tbl_BarInfo_PARM,SqlDbTy pe.Bit,1));
clubcmd.Parameters[Globals.User_tbl_BarInfo_PARM].Value=strBarInfo;

and then finally where I get the exception error:

clubcmd.ExecuteNonQuery();
clubconn.Close();
clubdg.EditItemIndex=-1;
BindData();

"Scott Allen" wrote:
On Tue, 15 Mar 2005 10:09:02 -0800, "I am Sam"
<Ia****@discussions.microsoft.com> wrote:
Hi Scott Allen,

Thank you. You were correct. Now, I am finding extra space in the textbox
fields when I debug. As well I keep getting the following error message:

Input string was not in a correct format.
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.FormatException: Input string was not in a correct
format.


What is the type of the parameter the query expects?

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #6
On Tue, 15 Mar 2005 11:15:02 -0800, "I am Sam"
<Ia****@discussions.microsoft.com> wrote:
I don't know which field is causing the error exception the message comes up
when I set the the command as follows:


Sam: I'd investigate those bit fields first. I imagine the runtime is
trying to convert strBarInfo to a bool.

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #7
Yeah I noticed that and have changed the fields to bool. That isn't the
problem. I'm still looking into other causes.
"Scott Allen" wrote:
On Tue, 15 Mar 2005 11:15:02 -0800, "I am Sam"
<Ia****@discussions.microsoft.com> wrote:
I don't know which field is causing the error exception the message comes up
when I set the the command as follows:


Sam: I'd investigate those bit fields first. I imagine the runtime is
trying to convert strBarInfo to a bool.

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

231
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought...
14
by: mr_semantics | last post by:
I have been reading about the practise of casting values to unsigned char while using the <ctype.h> functions. For example, c = toupper ((unsigned char) c); Now I understand that the standard...
7
by: David P. Donahue | last post by:
What is the C# equivelant of the following VB: CType(controlTemplate, TextBox).Text = "" I'm basically trying to use a more general object as an argument in one of my functions and then change...
4
by: Vincent | last post by:
Regarding the dropdetect function, defined as follows: Sub dropdetect(DropFrm As Form, DropCtrl As Control, Button As Integer, Shift As Integer, X As Single, Y As Single) Is it possible to...
3
by: Giorgos Keramidas | last post by:
Part of the OpenSolaris source contains the following macro: 41 /* 42 * FRC2PCT macro is used to convert 16-bit binary fractions in the range 43 * 0.0 to 1.0 with binary point to the right of...
6
by: crook | last post by:
I have code below and it works properly but when I'm compiling it with "--pedantic" flag, GCC(3.4.2) shows such warning: "ISO C forbids casting nonscalar to the same type". How can I change this...
13
by: WALDO | last post by:
I have a .Net TextBox (TextBoxBase, really) in which I am appending about 20 lines of text per second. I use the AppendText() method to accomplish this. This is a great substitute for taking the...
17
by: sophia.agnes | last post by:
Hi , I was going through peter van der linden's book Expert C programming, in this book there is a section named "How and why to cast" the author then says as follows (float) 3 - it's a...
22
by: Bill Reid | last post by:
I just noticed that my "improved" version of sscanf() doesn't assign floating point numbers properly if the variable assigned to is declared as a "float" rather than a "double". (This never...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.