how do i convert a timespan to a string in visual studio - visual-studio-2010

It gives an error,
Exception Details: System.InvalidCastException: Conversion from type 'TimeSpan' to type 'String' is not valid.
Time.Text = datareader1.GetValue(3)
I'm trying to display the data from the database(MS ACCESS), the data display is a time type.

Just call ToString():
Time.Text = datareader1.GetValue(3).ToString()
The fact that you're currently seeing this at execution time suggests that you've got Option Strict set off. (I'm assuming this is VB.) I would suggest having Option Strict on unless you really, really need it off for deliberate late-binding reasons.

Related

Why "Missing return statement" is not handled in languages?

Today I was getting introduced to Dart myself. At a point while playing with it, something was going wrong. Later I found that it was nothing but I forgot to put return statement in a function so null was set to the variable that was supposed to get value from that function.
At that point I was thinking, in Java it would be caught as error in the very first place. Why C/C++ or the new Dart don't add this feature? Does this feature slows the code down at a large scale? Or there are any other technical reasons behind this?
Every method returns a value, and if there is no return it is null.
However it looks like this some enhancements could be done in the future. See issue 73 : Missing return statement does not trigger warning or error and issue 13373 : Can get the editor to warn when there is no explicit return for a function returning a type.

Exception DateTime OleDbParameter

I’m using Visual Studio 2010. Within the project we add a DataSet, inside it; we have a Query Table Adapter to do all the queries to a SQL Server 2000 Data Base. One of the queries is formed using a Stored Procedure that receives four parameters. One of the parameters is a DateTime data type. Although we have check many times, we are receiving an unexpected exception:
Provider encountered an error while sending command parameter[0] '' value and stopped processing.
Conversion failed for command parameter[1] '' because the data value overflowed the type used by the provider.
Provider encountered an error while sending command parameter[2] '' value and stopped processing.
Provider encountered an error while sending command parameter[3] '' value and stopped processing.
Provider encountered an error while sending command parameter[4] '' value and stopped processing.
Working around this, if we delete the DateTime parameter of the Store Procedure, the query executes successfully otherwise we get the exception mentioned before.
We notice that the DateTime parameter has the property set as follows:
DbType: DateTime
ProviderType: DBTimeStamp
Any approach trying to accomplish the execution of the Query will be greatly welcome.
When I received this error, I had to change my date parameter to tell what the data type was.
Old Way
cmd.Parameters.Add(new OleDbParameter("TDate", DateTime.Now));
New Way
OleDbParameter dateParam = new OleDbParameter("TDate", OleDbType.Date);
dateParam.Value = DateTime.Now;
cmd.Parameters.Add(dateParam);

SQLite with WebMatrix.WebData.SimpleMembershipProvider Long to Int Cast Error

I'm trying to use the SimpleMembershipProvider with SQLite to enable authentication on my site. I have it initialized in my Global.aspx and can create users, however I can't log users in. I get the following error when I try to call WebSecurity.Login([UserName], [Password]):
Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
The stack trace is as follows (after I make the call to the Login function:
CallSite.Target(Closure , CallSite , Object ) +146
System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +661
WebMatrix.WebData.SimpleMembershipProvider.VerifyUserNameHasConfirmedAccount(IDatabase db, String username, Boolean throwException) +315
WebMatrix.WebData.SimpleMembershipProvider.ValidateUser(String username, String password) +162
WebMatrix.WebData.WebSecurity.Login(String userName, String password, Boolean persistCookie) +32
I know that SQLite only allows Int64 values in numeric columns (that aren't float). The question is: how do I get the SimpleMembershipProvider to work with Int64 values? I had a look at the source code for the offending routines listed in the stack trace and it seems that all numbers are being explicitly cast before being returned from their Int32 functions. However, I don't have the source to System.Dynamic.UpdateDelegates.UpdateAndExecute1 or CallSite.Target, so I can't see what is going on there. What is more, those are probably pre-compiled. So, the question remains, how can I get this to work?
The SimpleMembership Provider only supports SQL Server and SQL Compact 4.0. SQLite is not supported. If you want to use SQLite, you will have to create your own implementation of ExtendedMembershipProvider. You can more or less copy SimpleMembershipProvider.cs, and just modify the bits where the data type conflict arises.

Why am I getting an 'Invalid property value' err 380, VB6, VSFlexGrid.buildcombolist?

I'm brand new to working with VB6, and I'm trying to debug an err 380. The error occurs during a call to a function from VSFlexgrid used, and I've found very little specific documentation on the function involved: VSFlexgrid.BuildComboList.
I'm developing in a VM running win XP, and the software usually runs on Win7, so I don't think it falls in the compatibility issue I've seen on SO already.
The portion of code where it occurs happens multiple times in the program without fault, but only occurs on a particular action.
Does anyone know what might be causing the error specifically (or in general with these types of functions)? Is it a property of RecordSets that is triggering an error that I probably don't know about (very new to vb6)? I've confirmed that the parameters to BuildComboList aren't empty/null when the error occurs. My suspicions are with the recordset though....
Some Code:
Public Function LoadFlexCombo(grd As VSFlexGrid, conpassedconnection As Connection,
StoredProcedureName As String, FieldList As String, Optional keyfield As String,
Optional LookupName As String, Optional colKey As String, Optional UDFFilterValue As
String)
...
grd.BuildComboList(rs, FieldList, keyfield) 'bails out to error handler here.
...

DbLimitExpression requires a collection argument

Does anyone have the faintest idea what this error means please and how to resolve it? All my research is drawing a blank, I can see how to set it on MSDN but it doesn't explain it in a way that explains to me what the issue is. If I remove some of my LINQ queries to set viewbag items then it seems to resolve it but the moment I set new ones and pass them into my view to generate a mail for MVCMailer it comes back. Not sure if its a viewbag issue or simply that I am calling too many linq queries to generate them to pass to the view.
I am very stuck (again)..........
Cheers,
Steve.
DbLimitExpression requires a collection argument.
Parameter name: argument
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: DbLimitExpression requires a collection argument.
Parameter name: argument
An example of the code is:
var VBSalutation = from A in context.Salutations
where A.SalutationId == policytransaction.SalutationId
select A.SalutationName;
ViewBag.Salutation = VBSalutation.FirstOrDefault();
This is repeated for various parameters and then passed to the view.
Well, I faced a similar problem and solved it. Problem was in WHERE clause: data type of left side equal operator (=) sign was not matching with data type of right side. So in your scenario:
where A.SalutationId == policytransaction.SalutationId
SalutationID of A might be an INT and SalutationId of policytransaction might be a string (This is how it was in my case).
I solved it by assigning policytransaction.SalutationId to an Int variable and using it:
int myIntVariable = Convert.ToInt16(policytransaction.SalutationId);
...//some code here
where A.SalutationId == myIntVariable;
Please also note that you cannot directly cast your variables directly in Linq else you'll get an error "LINQ to Entities does not recognize the method". You'll have to use a temp variable and then apply the where clause.
Try ViewBag.Salutation = VBSalutation.SingleOrDefault();

Resources