Type MisMatch Error With String

I am getting a type mismatch error for some reason with my string field. I dont understand why because pretty much ANY value I put in should be valid for a string.



1    UpdateCommand = "UPDATE    Schedule SET  Professor_ID = @Hidden_Professor, Course_Start_Time = @Hidden_Start_Time.Value, Course_ID = @Hidden_Course, Campus_ID = @Hidden_Campus, Term_ID = @Hidden_Term, Course_Days = @Hidden_Days WHERE (Schedule.ID = ?)  "    
4        <asp:TemplateField >
5        <EditItemTemplate>
6                <asp:HiddenField ID ="Hidden_Start_Time" runat ="server" Value ='<%# Bind("Course_Start_Time") %>'  OnPreRender ="HiddenStartTime_OnPreRender" />
7                <asp:TextBox runat ="server" Width ="20" MaxLength ="2"   ID ="Start_Hour" OnTextChanged ="HiddenStarTime_OnChange"></asp:TextBox>
8                <asp:Label ID="Label4" runat ="server" Text =":"></asp:Label>
9                <asp:TextBox ID ="Start_Minute" Width ="20" MaxLength ="2"   OnTextChanged ="HiddenStarTime_OnChange"  runat ="server"></asp:TextBox>
10               <asp:DropDownList runat ="server" ID="Start_TimeOfDay" OnTextChanged ="HiddenStarTime_OnChange" >
11               <asp:ListItem Value ="AM">AM</asp:ListItem>
12               <asp:ListItem Value ="PM">PM</asp:ListItem>
13               </asp:DropDownList>
14       </EditItemTemplate>
15       </asp:TemplateField> 


Course_Start_Time    Text 

That was copied from my access database showing the type from the field. Just to give you an idea what all this code is doing basically  using two input boxes and 1 drop down list I am creating Military time from the 3 controls. Therefore if someone inputs [4]:[12] [PM] in the controls Hidden_Start_Time returns  16:12 as a string.



 protected void HiddenStarTime_OnChange(object sender, EventArgs e)
            TextBox hour = (TextBox)DetailsView1.FindControl("Start_Hour");
            TextBox minute = (TextBox)DetailsView1.FindControl("Start_Minute");
            DropDownList timeofday = (DropDownList)DetailsView1.FindControl("Start_TimeOfDay");
            int hours = Convert.ToInt32(hour.Text);
            int minutes = Convert.ToInt32(minute.Text);
            string buildstring = "";
            HiddenField hiddenstart = (HiddenField)DetailsView1.FindControl("Hidden_Start_Time");

        if (Convert.ToInt32(hour.Text) > 0 && Convert.ToInt32(minute.Text) >= 0 && hour.Text.Trim().Length > 0 && minute.Text.Trim().Length > 0)
            if (timeofday.SelectedValue.IndexOf("PM") != -1)
                hours += 12;
            hiddenstart.Value = hours.ToString() + ":" + minutes.ToString();
            int thehours = (int)DateTime.Parse(hiddenstart.Value).TimeOfDay.TotalHours;

            if (thehours <= 9)
                buildstring += "0" + thehours.ToString();
                buildstring += thehours.ToString();

            if (DateTime.Parse(hiddenstart.Value).Minute <= 9)
                buildstring += ":" + "0" + DateTime.Parse(hiddenstart.Value).Minute.ToString();
                buildstring += ":" + DateTime.Parse(hiddenstart.Value).Minute.ToString();

            hiddenstart.Value = buildstring;
         hiddenstart.Value = "";


Sorry I know its a bit messy but just wanted to show you that the Hidden control value is equal to the military time formated string. So I dont understand how can there be a possible MisMatch of types.

1/6/2008 6:21:10 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 52

Without having read your entire post, I think I see an issue...  Do you think "@Hidden_Start_Time.Value" is a problem?  I'll keep looking at what you posted, but at first glance, that looks like a syntax error.

MCAD .Net (70-315, 70-320 & 70-229)
:One that throws dirt loses ground:
1/6/2008 7:20:40 AM

I dont believe that is the problem because EVERY other control that I am passing the values into the query string I never used .Value or .Text. And I even tried adding .Value to see if it could possible be the issue and it still doesnt work. 

1/6/2008 7:32:05 AM

any other suggestions?

1/6/2008 6:41:10 PM

Sure, can you profile the query to see what values are making it do SQL server?  Perhaps a parameter isn't being substituted.  If you can't profile, can you write out the values and build the sql manually?  Does it work like that?

MCAD .Net (70-315, 70-320 & 70-229)
:One that throws dirt loses ground:
1/6/2008 8:08:26 PM

Similar Artilces:

System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
I'm getting an error while trying to use the wizard to create a form and than pass it the vaibles to Mail. Any help would be much appreciated. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try {   message.From = txtEmail.Text; message.To.Add("admin1@yoursite.com"); message.Subject = "Feedback"; message.CC.Add("admin1@yoursite.com"); message.CC.Add("admin2@yoursite.com"); message.IsBodyHtml = false; message.Body = txtMessage.Text; smtpClient.Send(message); lblStatus.Text = "Email successfully sent."; } catch (Exception ex) { lbl...

string[] type property has error in my control!! why?
[DefaultProperty("EnablePage"),DefaultEvent("OnQuery"), ToolboxData("<{0}:QueryCom runat=server></{0}:QueryCom>")] [Designer(typeof(QueryDesigner))] [ParseChildren(true,"ExceptCols")] [PersistChildren(false)] public class QueryCom : System.Web.UI.WebControls.WebControl,INamingContainer { private String[] arrayExcept = new String[50]; ..... [Bindable(true),Category("Query"),Description(""), DesignerSerializationVisibility (DesignerSerializati...

Error Type mismatch for field ,expecting: WideString actual: String
Hello all: Platform: Delphi XE5 Enterprise Database: Firebird 2.5 I've a query with a persistent Field. If execute in Design mode, work ok. In execution time i received Error Type mismatch for field ,expecting: WideString actual: String . In conection.params I've add Params.Values['UseUnicode'] := 'False'; Thanks in advance Alfonso Presa wrote: > Hello all: > > Platform: Delphi XE5 Enterprise > > Database: Firebird 2.5 > > I've a query with a persistent Field. > > If execute in Design mode, work ok. &g...

Custom Control Error: Cannot Create Object of Type Panel From Its String Representation.
I have created a custom control and added a property of type panel to it. In the designer this property shows up as a drop down list with all the panels in the page. When I select a panel, the control disappears with a render error stating that it cannot create object of type panel from its string representation. I can however set the property from code behind by giving the property a reference to the panel, but not from designer.   Hi,You must create a TypeConverter  that can convert a string containing a control ID to the corresponding Panel instance.Then you must register...

Data type mismatch in criteria expression error when using a DetailsView control in VWD2005 on access DB
I have a Yes/No field in an Access 2000 db that im using to show a simple yes/no checkbox on a web form in VWD2005. When I click the insert link, Im getting the error "Data type mismatch in criteria expression". I believe this is because the form is giving ADO.NET true/false instead of yes or no. Is this correct? And how do I make it so Access will accept the input from a checkbox in a detailsview control? Thanks! -Matt Yes you are correct. The check box checked is a boolean value that is 1 if true and 0 if false. You can hardcode the yes/no in the insert command just pu...

Error: Cast from type DBNull to type String is not valid
Hi,I get the following error when I try to convert to string.  I know for a fact that the result "UniversityMajor" is empty at this point (null), and that's why I got this error, but I get it even after checking If Not IsDBNull(.UnivMajor)....plz helpThanks,System.InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid.Source Error: Line 732: With ApplicationPart2 Line 733: If Not IsDBNull(.UnivMajor) Then Line 734: .UnivMajor = CType(result("UniversityMajor"), String) Line 735: End If Line 736: ...

Cannot install Toolbox with VS 2005 -error message: Control cannot be created because Visual Studio cannot find the control's type in the control assembly.
I unzipped the toolkit, and followed the instructions on the setup page to add the controls but when I try to create a control (double-clicking the control in the toolbox) I get the error message: Control cannot be created because Visual Studio cannot find the control's type in the control assembly.  I have the April release of Atlas.  I tried adding the AtlasControlToolkit to the bin folder of my website but that didn't help. Hi - Another user reported this problem but has some steps to resolve it: http://forums.asp.net/thread/1256261.aspx Could you try those steps and r...

Stored Proc Error: error converting character string to smalldatetime data type
I am trying to create a page that adds users to a MS SQL database. In doing so, I have run into a couple errors that I can't seem to get past. I am hoping that I could get some assistance with them. Error from SQL Debug: --- Server: Msg 295, Level 16, State 3, Procedure AdminAddUser, Line 65 [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting character string to smalldatetime data type. --- Error from page execution: --- Exception Details: System.Data.OleDb.OleDbException: Error converting data type varchar to numeric. Source Error: Line 77...

Control and type from string
into an xml file I gat infos fotr loading controls and valid types>>> <DataType>Int32</DataType> <ControlType>TextInteger</ControlType> now in sted of doing >>> if ControlType = "TextInteger" then value = Cint(cType(anyFoundControl, TextInteger).text) end if TextInteger is a control inherited from textBox I have TextString, TextFloat , ...... how can I do >>> convert(ctype(anyFoundControl, ControlType).text), DataType) ?? thank you angiras The nearest equivalent that comes to my mind is ...

How do you to resolve type 'DBNull' to type 'String' is not valid error?
Hi there, Im reading data from a SQLServer table and some fields are blank. When my code reads them, I get the following error: Cast from type 'DBNull' to type 'String' is not valid. on my command: strDates = oReader("TRA_Dates") Any idea how to prevent it? thanks Redeem Redeem. If Not IsDBNull(oReader("TRA_Dates")) Then strDates = oReader("TRA_Dates") You could also alter the T-SQL to convert nulls to empty strings, but that's really more of a business rule than a data rule....

Why am i getting an error runtime error conversion string type "pr_h_reqby" to int
here is my code the falue of pr_h_reqby is "Test"  Dim strconn As New SqlConnection(connstring) Dim myReqdata As New DataSet Dim mycommand As SqlDataAdapter Dim sqlstr As String = "select pr_H_reqby from tbl_pr_header where pr_h_recid = " & recid & "" mycommand = New SqlDataAdapter(sqlstr, strconn) mycommand.Fill(myReqdata, "mydata") If myReqdata.Tables(0).Rows.Count > 0 Then 'lblReqID.Text = myReqdata.Tables(0).Rows("reqid").ToString lblNameVal.Text = myReqdata.Tables("mydata").Rows("pr_H_reqby").ToString() lblEmailVal.Text = myReqdata.Tables("mydata").Rows(...

Cast from type 'DBNull' to type 'String' is not valid. Error
Hi, Can anyone help me with an error I am receiving "Cast from type 'DBNull' to type 'String' is not valid."  I am creating an aspx page in VB.NET, please find attached code causing error.objCmd = New SqlCommand("USP_DisplayEmbarkDetails", objConn)  objCmd.CommandType = CommandType.StoredProcedure  objCmd.Parameters.Add("@BranchID", lblGetBranchID.Text)  objConn.Open()  objRdr = objCmd.ExecuteReader()    While objRdr.Read     lblBranchName.Text=objRdr("BranchName")    lblBranchID.Text=objRd...

Bound TextBox error: Conversion from type 'DBNull' to type 'String' is not valid
 Hi,I use DataSet designer to generate my strongly typed datasets and to bind my FormView to a Business Layer (BLL). The BLL uses the generated Dataset classes. I have a column  in the DB of type string. The column is bound to a textbox like this:Text='<%# Bind("Local") %>'  If the column has a value, thingts work well, but  When the column has a null value, I get the error: Conversion from type 'DBNull' to type 'String' is not validWhat can I do Please? Thanks a lot, I appreciate your taking the time to help me. ...

receive error opening page Conversion from type 'DBNull' to type 'String' is not valid.
Hello, I receive the error below when opening up a page with a FormView1 control.  The page has a cascading Drop Down List Error: Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'String' is not valid.  Stack Trace: [InvalidCastException: Conversion from type 'DBNull' to type 'String' is not valid.] Microsoft.VisualBasic.CompilerServices.Conversions.ToString(Object Value) +625 Members_frmStudent.ddlSubSystem_DataBound(Object sender, EventArgs e) +213 System.Web.UI.WebControls.Bas...

Web resources about - Type MisMatch Error With String - asp.net.presentation-controls

Spatial mismatch - Wikipedia, the free encyclopedia
Spatial mismatch is the mismatch between where low-income households reside and where suitable job opportunities are available. In its original ...

Skills mismatch behind youth jobless: B20
Making graduates more attractive to employers is key to reducing youth unemployment, a conference heard today.

Retirement dreams a mismatch with savings reality
Australians have unrealistic expectations about the lifestyle they will be able to afford in retirement.

The perfect mismatch
The perfect mismatch

Newcastle Next: Powerful mismatch of architectural styles
WILL Newcastle be all that different from the Newcastle we see now, or the one 100 years ago?

Soccer mismatch
Dutch scientists claim that mistakes are inevitable when assistant referees are judging whether soccer players are offside or not. Raôul R. ...

Free to play iOS game marketing cost ‘mismatch is insane’
Free-to-play iOS game makers say the mismatch is “insane” between what it costs to acquire a new customer and how much revenue they’ll get through ...

Skills mismatch or ‘labour market failure’? Canada’s newcomer conundrum
In the past seven years, the number of people brought to Canada to do a job and then leave has eclipsed the number of people moving here annually ...

PBO: Canada's Labour Shortage, Skills Mismatch Don't Seem To Exist
OTTAWA - Canada's budget watchdog says there's little evidence of serious labour shortages or a skills mismatch problem in the country.The finding ...

... itself. The company treats the stores as a sales channel but also as a communications channel with its customers. A complete and total mismatch. ...

Resources last updated: 11/27/2015 1:49:59 PM