.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Convert string value to type and pass as type parameter.

Posted By:      Posted Date: November 20, 2010    Points: 0   Category :ASP.Net


In the below code... i am getting all filenames from a directory.  parsing out the directory names & the .vb extension. . . then converting those filesnames to classes.  Every file in the LPCriteria direcotry is its own class with a "Evaluate" function.

The problem comes in here:

Dim boolFlagged As Boolean = CType(MyInstance, objType).Evalua

Because the "objType" comes up as "type 'objType' is not defined".   the parameter requested is "Object as Type".  But i dont know the type, as it is really the name of the file...       any ideas how i get this parameter passed in?   Thanks! :)

Dim strPath As String = System.AppDomain.CurrentDomain.BaseDirectory()
Dim files As String() = System.IO.Directory. _
     GetFiles(strPath & "App_Code\GeneralClasses\LPCriteria\", "*")


View Complete Post

More Related Resource Links

error: cannot implicitly convert type 'string' to 'int?'

Hey guys,I am trying yo build the following class for which i get an error on the line this.id = e.id as cannot implicitly convert type 'string' to 'int?'. can anybody help me with it??many many Thanks,Chetan.using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Data.Linq;using System.Text;using System.Runtime.Serialization;using HsInternet.Data.DAL;namespace HsInternet.Data.BLL{    public class Baby    {        public int id { get; set; }        public string name { get; set; }        public string parents { get; set; }        public int gender { get; set; }        public string weight { get; set; }        public string length { get; set; }        public DateTime date { get; set; }        public DateTime time { get; set; }        public string image { get; set; }        public string ipa { get; set; }        public string ipb { get; set; }        public Baby()  &

Unable to convert type System.String to System.Web.DynamicData.MetaTable



I am encountering the problem  "Unable to convert type System.String to System.Web.DynamicData.MetaTable" when I hit one of the tables for List.aspx.  It is using the DynamicData/PageTemplates/List.aspx and this error is not happening in other tables.

It is happening on the line

GridView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context));

If you have any leads, please let me know.



Is it possible to pass an array of values, or a custom type as a parameter?


I am using a web service as a datasource.  When I create my report I would like to pass
a string array to this web method to retrieve the data for the report.  Is this possible or is there
a similar way to do this such as passing a custom type?





type object parameter



I have a problem I can't figure out.

I've been trying to add a listbox with multi select enabled as a parameter to my select statement in sqldatasource.

So i created a function like this :

string strItemTypes = "";
foreach (ListItem li in lbItemType.Items)
   if (li.Selected)
      strItemTypes += "," + li.Value;
strItemTypes = strItemTypes.Substring(1);

which gives me the selected items like this for example : "1,2,3"...
Then I've been trying to add it to my sql select statement :

SELECT tblOfficesItems.idOfficesItems, tblStockItems.Name, tblStockItems.Description, tblStockItemTypes.TypeItem, tblStockItems.Notes FROM tblOfficesItems INNER JOIN tblStockItems ON tblOfficesItems.fkItem = tblStockItems.idItem INNER JOIN tblStockItemTypes ON tblStockItems.fkTypeItem = tblStockItemTypes.idTypeItem WHERE tblStockItems.fkTypeItem IN ( @fkTypeItems )

using a hiddenfield with a controlparameter of type=object
but it just don't seem to work, seems like the data just won't bind or something and I don't get any errors so I'm confused!!

then i tried this :

SELECT tblOfficesItems.idOfficesItems, tblStockItems.Name

Cannot convert type 'object[]' to 'byte[]'


I am doing this .. and i want to convert object array to byte array. How should I do that?

Object[] myVal = um.myData;

Byte[] byteArray = (Byte[])myVal;

Failed to convert parameter value from a String to a Guid.


I am trying to get the UserRole from the logged in user and send it to the database table my code is:

SqlParameter FamilyFriendsOther = new SqlParameter("@Role", SqlDbType.UniqueIdentifier);
        string [] roles = System.Web.Security.Roles.GetRolesForUser();
        if (roles.Length > 0)
            FamilyFriendsOther.Value = roles[0];

Conversion from string to type 'Date' is not valid



Im receiving a strange error Error Message: Conversion from string "15/08/2010 22:21:35" to type 'Date' is not valid.

I know this is generally down to cultural date formats etc, however the reason this is strange is it just randomly occured twice in the last week, the website has been running since october and nothing has changed,

The error constantly occured until the IIS was reset and recompilled the site, its been running fine since, however im just trying to figure out what could cause such an error to occur.

I've narrowed it down to a line of code which is:

bktime = DReader.Item("Bktime").ToString

bktime = Year(CDate(bktime)) & "-" & fmt(Month(CDate(bktime)), 2) & "-" & fmt(Day(CDate(bktime)), 2)

Has anyone else encountered this randomly occuring and is there anything i can put in place to prevent this in future?



Cannot implicitly convert type


        public SqlDataReader GetModelbyModelID(int modelID)
            Database db = DatabaseFactory.CreateDatabase();
            string sqlCommand = "GetModelbyModelID";
            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
            db.AddInParameter(dbCommand, "modelID", DbType.Int32, modelID);
            SqlDataReader dataReader = db.ExecuteReader(dbCommand);    ***********************
 return dataReader; }

I am getting the followind error????

Error    27    Cannot implicitly convert type 'System.Data.IDataReader' to 'System.Data.SqlClient.SqlDataReader'. An explicit conversion exists (are you missing a cast?)    E:\projects\models\App_Code\dataProfile.cs    780    40    E:\projects\models\

Failed To Convert Parameter Value From A String To A Int32

 This is my stored procedure: PROCEDURE[dbo].[uspEXPENDITURE_DETAILS] ( @ExpDetailsID int=0 output, @ExpDet_ExpID int, @ExpDet_Municipality_ID nvarchar(50), @ExpDetGeneralFund money, @ExpDetSpecialRevenue money, @ExpDetCapitalProjects money, @ExpDetTotal money, @Exp_Reporting_Year varchar(10), @ExpComments varchar(max), @Contact_ID int ) AS BEGIN  -- SET NOCOUNT ON added to prevent extra result sets from  -- interfering with SELECT statements.  SET NOCOUNT ON; deletefrom [dbo].[TBL_EXPENDITURE_DETAILS] where ExpDet_ExpID=@ExpDet_ExpID and ExpDet_Municipality_ID=@ExpDet_Municipality_ID and Exp_Reporting_Year=@Exp_Reporting_Year If@ExpDetailsID >= 0 Begin INSERT     INTO [dbo].[TBL_EXPENDITURE_DETAILS] ([ExpDet_ExpID] ,[ExpDet_Municipality_ID] ,[ExpDetGeneralFund] ,[ExpDetSpecialRevenue] ,[ExpDetCapitalProjects] ,[ExpDetTotal] ,[Exp_Reporting_Year] ,[ExpComments] ,[ExpDetCreatedBy] ,[ExpDetCreateDate]) VALUES  (@ExpDet_ExpID , @ExpDet_Municipality_ID , @ExpDetGeneralFund, @ExpDetSpecialRevenue , @ExpDetCapitalProjects, @ExpDetTotal, @Exp_Reporting_Year, @ExpComments, @Contact_ID, GetDate () )    SET @ExpDetailsID = SCOPE_IDENTITY()  return @ExpDetailsID end   Public Sub CreateExpenseDetails() Dim item As GridViewRow Dim txtExpGenFund, txtExpD

failed to convert parameter value from a string to a int32

I am not sure where my app is failing but most probably this is where it is failing.. I think lblExpID.Text is the culprit. Here's the relvant part of my code: Dim lblExpID As Label For Each item In LSGrid.Rows lblExpID = item.FindControl("lblID") If txtExpGenFund.Text <> "" Then sqlArray(i) = ExpDetailsID & "," & (lblExpID.Text) & "," & MunID & "," & _ Val(txtExpGenFund.Text) & "," & Val(txtExpDetSpecialRevenue.Text) & "," & _ Val(txtExpDetCapitalProjects.Text) & "," & expTotal & "," & reportingYear & "," & "Test Comments" & "," & UserID End If Can u help me identify why i am getting this error looking at the sp below: PROCEDURE [dbo].[uspEXPENDITURE_DETAILS] ( @ExpDetailsID int=0 output, @ExpDet_ExpID int, @ExpDet_Municipality_ID nvarchar(50), @ExpDetGeneralFund money, @ExpDetSpecialRevenue money, @ExpDetCapitalProjects money, @ExpDetTotal money, @Exp_Reporting_Year varchar(10), @ExpComments varchar(max), @Contact_ID int ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; delete from [dbo].[TBL_EXPENDITURE_DETAILS] where ExpDet_ExpID=@ExpDet_ExpID and ExpDet_Municipality_ID=@ExpDet_Municipality_ID and Ex

How can I access a Type with generic parameter in XAML

Hello, How can I access a Type with generic parameter in XAML. class SampleClass<T> { } now in XAML: i want to access xmlns:local="Ref to SampleClass" How it will create the instance of SampleClass<T>?

How to convert System.Type to Data.DbType?

Hi,Is it possible to convert a System.Type to Data.DbType (this is unfortunately an enumaeration)?Thanks, Rainer.

Unable to enter the product key in the Convert License Type page (textbox is read-only)

We installed both WSS and MOSS SP2 and had planned to follow the manual fix for the known issue that the patch unexpectedly activates a trial expiration.  However, the textbox to enter the product key is read-only.  We have tried accessing this page using the normal administrator credentials as well as the farm account; no success.The SP2 issue and manual fix is detailed here, http://support.microsoft.com/default.aspx/kb/971620We were able to experience this problem on a farm running the Feb 2007 cummulative patch (version so it's not related to the SP.  But running the SP increasing the need to find the fix.Any help is appreciated,J. Aqui

Conversion from type 'TextBox' to type 'String' is not valid

I have a FormView that allows a user to register for a company event. I want to do a couple of things with this form. 1. I need to write this data to a MS SQL database 2. I need to send an email confirmation of their registration to their email. I know how to do both of these things, but i am having trouble doing both at the same time. It would be nice if I could do it in one click, but I coded it into two pages to try to help simplify it. The first page allows the user to input their information into a formview and when they click the submit button, it places those answers into session variables:Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Session("FirstName") = Me.FormView1.FindControl("FirstName") Session("LastName") = Me.FormView1.FindControl("LastName")  <li> <label> First Name</label> <asp:TextBox ID="FirstName" runat="server" class="text-box" Text='<%# Bind("FirstName") %>' /> </li> </ul> </div>

How to pass a String and convert to xml

A Simple Query Pass to connection String 1 My Query is SELECT a.HD, a.HEAD, a.SH, a.SUBHEAD, a.TRK, a.TRACK, a.TGT, a.TARGET, a.PDC, a.DT_RELEASE, a.STATUS, a.COFROM V_HIERARCHY1 a   2,My Data is HD    HEAD    SH    SUBHEAD    TRK    TRACK    TGT    TARGET    PDC    DT_RELEASE    STATUS    COHR    HR    Rec    Records    Leave    Leave Records    HRL.0002    Quarterly Review    01.07.2010    04.07.2010    Planned    EdlinkHR    HR1    DB    Database    SAL    Salary    DDS.0001    Calculation of Monthly salary    08.08.2010    09.08.2010    WIP    EdlinkHR    HR    Rec    Records    Ind    Induction Records    HRI.0001    Completion of dossiers.    08.07.2010    10.07.2010    WIP    EdlinkHR    HR  

Calling a method with a class object as parameter data type.

   [WebMethod]    public string GetInfo(Customer inCust)    {        // Code in here    } I have a web service that resides on a remote server. I want to call a public method of theweb service named  "GetInfo". The method is shown above. The web service method expects a class object oftype "Customer". What I did to create a Customer object was to define in my asp.net project my own class named "Customer" which is exactlythe same as the class that belongs to the web service project on the remote server. I then created an instance of Customerand tried to call the web service passing in an object of type customer : my.Service ws = new my.Service(); // Get web service connectionCustomer aCustomer = new Customer();aCustomer.Initialize();ws.GetInfo(aCustomer) // call web service passing in a Customer object The problem is that the compiler gives me the following error: Value of type '_Default.Customer' cannot be converted to 'ws.Class1'. Here Default is refering to my Default.aspx.cs code. Why is this? Do I need to Cast my "aCustomer" class object to a type ofws.Customer ? How do I do that?

Cannot Implicitly Convert Type Ilist to List

Hi All, In the below code i get the Following Error, Cannot implicitly convert type 'System.Collections.Generic.List<Nous.nSpeckEnterprise.GetEnterpriseComponent_Result>' to 'System.Collections.Generic.IList<Nous.nSpeckEnterprise.Component>'. An explicit conversion exists (are you missing a cast?)   <br/> NSTTT_CRRISQ_TESTEntities entities = new NSTTT_CRRISQ_TESTEntities();<br/> IList<Component> Components = new List<Component>();<br/> var c = entities.GetEnterpriseComponent(componentId).ToList();<br/> <strong>Components = c;<br/> </strong> return Components;   Can anyone help me how to do teh cast.......Thanks  
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend