Cannot implicitly convert type 'System.Data.DataTable' to 'System.Data.Dataset'

I am using an excel spreadsheet as a data source to build a dataset which is then used to populate a grid: 

I am getting the following error: Cannot implicitly convert type 'System.Data.DataTable' to 'System.Data.Dataset'

Here's my code:

private DataSet GetData(String description, String mpnumber, String link)

{

//MPData will represents the Data in Application Cache. We will use Cache Data

//for performance purposes, because MP Information will not change often. I choose

// to also use Dataset Filtering instead of SQL Server Filtering. However the DataAccess layer should

// remain parameterized to allow others to filter the data in the database.

DataSet MPData;

//Get Cache

if (Cache["MPData"] != null)

{

MPData = (
DataSet)Cache["MPData"];

}

else

{

//Get Data From Data Access and Cache

try

{

//Get Data

MPData = VFileDataGetter.GetMPData(description, mpnumber);

 

//Recreate the Item in Cache and hold for 30 minutes. Consider Adding to config file

Cache.Insert("MPData", MPData, null, DateTime.Now.AddMinutes(CACHE_TIME), TimeSpan.Zero);

 

}

catch

{

//Catch Error and return a Null Dataset

return null;

}

}

//Return Data Set

return MPData;

}

Here is my code from DataAccess.cs:

public class VFileData

{

public DataTable GetMPData(string searchMPNbr, string searchDescription)

{

// Create connection string variable.

string sConnectionString = HttpContext.Current.Server.MapPath(@"~\App_Data\") + ConfigurationManager.AppSettings["VPortFieldMaintFilePath"];

// Create connection object by using the preceding connection string.

OleDbConnection objConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + sConnectionString + @"; Extended Properties=""Excel 12.0;HDR=Yes"";");

// Open connection with the database.

objConn.Open();

// The code to follow uses a SQL SELECT command to display the data from the worksheet.

// Create new OleDbCommand to return data from worksheet.

OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);

// Create new OleDbDataAdapter that is used to build a DataSet

// based on the preceding SQL SELECT statement.

OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

// Pass the Select command to the adapter.

objAdapter1.SelectCommand = objCmdSelect;

// Create new DataSet to hold information from the worksheet.

DataSet objDataset1 = new DataSet();

// Fill the DataSet with the information from the worksheet.

objAdapter1.Fill(objDataset1, "Field_Maintenance_Procedures");

DataTable searchlist = objDataset1.Tables[0];

searchlist.DefaultView.Sort = "MP Number";

searchlist.DefaultView.RowFilter = "[MP Number] LIKE '%" + searchMPNbr + "%' or Description LIKE '%" + searchDescription + "%' ";

searchlist.DefaultView.RowFilter = "[MP Number] LIKE '%" + searchMPNbr + "%' and Description LIKE '%" + searchDescription + "%' ";

// Clean up objects.

objConn.Close();

return objDataset1.Tables[0];

}

 

}

 

0
atma
1/22/2009 4:55:06 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

2 Replies
11775 Views

Similar Articles

[PageSpeed] 2
Get it on Google Play
Get it on Apple App Store

Hi,atma

That IS because GetMPData is returning datatable and MPData is dataset

and u r using this

atma:
MPData = VFileDataGetter.GetMPData(description, mpnumber);

That is u r tring to convert datatable to dataset.

So try to make type same.fo r that

 

 


RAGHAV

MVP ASP/ASP.Net Read My Blog


MARK THE POST AS ANSWER IF IT HELPS U.


"Success doesn't come to you…you go to it."--Marva Collins




"Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


1
raghav_khunger
1/22/2009 5:07:50 PM

Thanks.

-1
atma
1/22/2009 6:07:59 PM
Reply:

Similar Artilces:

convert type 'System.Data.DataSet' to 'System.Data.DataTable'
 I got this error  : Cannot implicitly convert type 'System.Data.DataSet' to 'System.Data.DataTable' i have written code like thisDataTable dt = new DataTable(); dt = GetGalleryImages(name); Possibly coz GetGalleryImages returns a dataset and not a datatable? Try: DataSet ds = GetGalleryImages(name); what type does GetGalleryImages return?  If this returns a dataset then you will have to change datatable to dataset, then index the table of the dataset.Please mark as answer if you find helpful.Ustes G....

Error: foreach statement cannot operate on variables of type 'System.Data.DataSet' because 'System.Data.DataSet' does not contain a definition for 'GetEnumerator', or it is inaccessible
I am getting error on this line DataSet dsdata=new DataSet(); SQL="Seelct * from tablename"; //dsdata contains result of the above query foreach(DataRow dr in dsdata) //This line gives error Error: foreach statement cannot operate on variables of type 'System.Data.DataSet' because 'System.Data.DataSet' does not contain a definition for 'GetEnumerator', or it is inaccessible DataSet dsdata=new DataSet(); SQL="Select * from tablename"; //dsdata contains result of the above query foreach(DataRow dr in dsdata.Tables[0].Rows) //This ...

Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.
what is my problem? I'm working with GridView for sorting The error message is that "Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'".... Dim m_DataTable As DataTable = GridView1.DataSource How can I change the code above?   Well let's see, if your DataSource is a DataView, you can get its associated DataTable object using the .Table property: Dim m_DataTable As DataTable = GridView1.DataSource.Table or in a land of strict typing:  Dim m_DataTable As DataTable = CType(GridView1.DataSource, System.Data.DataView).Table   Hope tha...

Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.
When I click the sort hyperlink, I got this error mesg: Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.  in line 5.How do I fix this? Thanks. 1 Protected Sub GVCRlisting_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GVCRlisting.Sorting 2 GridViewSortExpression = e.SortExpression 3 Dim pageIndex As Integer = GVCRlisting.PageIndex 4 5 GVCRlisting.DataSource = SortDataTable(GVCRlisting.DataSource, False) 6 GVCRlisting....

Linq Error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Data.EnumerableRowCollection<System.Data.DataRow>'.
Hi I am using a AdventureWorks database and trying to use LINQ to query the data. i am not able to get the AsDataView() if i don't declare query as EnumerableRowCollection. But if i declare the query EnumerableRowCollection it shows me an error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Data.EnumerableRowCollection'. AdventureWorks.AdventureWorksDataContext db = new AdventureWorks.AdventureWorksDataContext(); EnumerableRowCollection query = from t in db.TransactionHistories.AsEnumerable() ...

Cannot implicitly convert type 'System.Data.DataTable' to 'TEntities'.
hi this i am getting: Error 2 Cannot implicitly convert type 'System.Data.DataTable' to 'TEntities'. An explicit conversion exists (are you missing a cast?) public class LookUpTables<TEntities> where TEntities : DataTable, new() { private SqlConnection con;private static LookUpTables<TEntities> instance;public static LookUpTables<TEntities> Instance { get { // Use 'Lazy initialization' if (instance == null) {instance = new LookUpTables<TEntities>(); }return instance; } } // Note: Constructor is 'private'...

convert type 'System.Xml.XmlDataDocument' to 'System.Data.DataSet'
I am using XMLDataDocument in web services which returns XMLDataDocument using this XMLDataDocument for Dataset in application getting error Cannot implicitly convert type 'System.Xml.XmlDataDocument' to 'System.Data.DataSet'  any idea  XmlDataDocument has DataSet property to get the document as a data set.Thanks,Teemu KeiskiFinland, EU  [WebMethod]    public XMLDataDocument xmldoc(DateTime x, DateTime y)    {        df = dateFrom;        dt = dateTo;   &...

'TypeConverter' is unable to convert 'System.Data.SqlClient.SqlConnection' to 'System.Data.SqlClient.SqlConnection'.
Hey, I was hoping someone could shed some light on this error for me. I am using the TypeConverter in the System.ComponentsModel Namespace, and when I attempt to take an object, which in this case is a SQLConnection, and perform a TypeConvert (code example below) I get the following error: Error: ---------------------------------------------------------------------------- 'TypeConverter' is unable to convert 'System.Data.SqlClient.SqlConnection' to 'System.Data.SqlClient.SqlConnection'. ---------------------------------------------------------------------------- ...

Value of type 'System.Data.Dataset' cannot be converted to 'String'
I receive the above error for line 57 which is: Address.text = Clientinfo(DropDownlist1.Items(DropDownList1.SelectedIndex).text) I'm trying to take the selected item from the dropdownlist1 and have the data from the query 'Clientinfo' appear using the label control called 'address'. I plan to format it to be used as a mailing address: 123 Street City, State Zip Etc. Obviously I am learning as I go. Can anyone give me an alternative or find my error. Much appreciated. The code is below: Sub Page_Load(Sender As Object, E As EventArgs) If Not Page.IsPostBa...

Cannot convert type 'myWebService.GetMyMethode' to 'System.Data.DataSet'
Hi all, I have a webservice that I call in my other application web. In my webservice, I have a method that return a DataSet. MyWebService new1 = new MyWebService();GridView1.DataSource = (DataSet)new1.GetMyMethod();GridView1.DataBind();  But I had this message : Cannot convert type 'myWebService.GetMyMethode' to 'System.Data.DataSet' I found the KB article number 815131 http://support.microsoft.com/kb/815131/ But this bug to apply  only to :   • Microsoft Visual C# .NET 2003 Standard Edition • Microsoft Visual C# .NET 2002 St...

Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRowView'.
Hi... I have a ListView which is nested in the ItemTemplate of another ListView. If a "status" value in the inner ListView = 1, then I'd like to hide the "Add to cart" link. However, the inner ListView's ItemDataBound event results in the error: "Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRowView'." I've thoroughly searched the forums, but have not found a solution to this seemingly straightforward problem. Here is the code; the error occurs at line 8. 1 protected void L...

Error : Value of type 'System.Data.DataTable' cannot be converted to 'String'
Hi, I have a compilation error : Value of type 'System.Data.DataTable' cannot be converted to 'String'. I want to erase all the records in my Access database and update it with a DataTable. My code lines : Dim conn As OleDbConnection Dim da As OleDbDataAdapter Dim ds As DataSet Dim sql As String sql = "SELECT * FROM menu;" conn = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=d:\www\tgc\prof_tech\fsthilaire\parametres_site\parametres_site.mdb" ) da = New OleDbDataAdapter(sql, conn) conn.Open() ds = New DataS...

Error: Value of type 'System.Data.CommandBehavior' cannot be converted to 'System.IAsyncResult'.
  I wrote this code to retrieve data from the database using autocomplete extender control. Dim Dr As SqlDataReaderDim RtData As List(Of String) = New List(Of String) Dr = MysqlCmd.EndExecuteReader(Data.CommandBehavior.CloseConnection) While Dr.Read()RtData.Add(Dr("CustName").ToString()) End While   Plz Help!   regards   yamani     The EndExecuteReader does not take a CommandBehavior.  The BeginExecuteReader does.  Please follow the example on the MSDN documentation:http://msdn.microsoft.com/en-us/library/kddf8ah6....

Error type 'System.Data.DataTable' to type 'PRODUCT_LISTDataTable'
I can't figure this one out. I created new solution in vs2005 from using vs2003 and I have a problem I can't find an answer to. I get the following error that relates to passing a system.data.datatable to a dataset.datatable named "ProductList.PRODUCT_LISTDataTable".  It says it can't cast the object from one type to the other, and I've tried "CType" and doesn't work. Error: Unable to cast object of type 'System.Data.DataTable' to type 'PRODUCT_LISTDataTable'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trac...

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...

c:\inetpub\wwwroot\WebApplication1\subject_info.aspx.vb(658): Value of type '1-dimensional array of System.Data.DataRow' cannot be converted to 'System.Data.DataRow'.
Hi everyone, I have a "select link" in one of the fields in the DataGrid. I want it retreive informations when i click on that link and display in the text box so i can modify data. The problem is i always have this error when i COMPILE: " Value of type '1-dimensional array of System.Data.DataRow' cannot be converted to 'System.Data.DataRow' ". Here's is my code: ************************************************ Private Sub UpdateDetails(ByVal uSubjectID As String) DaLecturer1 = Session("ds") Dim dt As DataTable = DaLectur...

Cannot convert type 'int' to 'System.Data.DataView'
I have the following SqlDataSource in my page:<asp:SqlDataSource ID="sqlds" runat="server" ConnectionString="<%$ ConnectionStrings:cs %>"    SelectCommand="SELECT [Quest1], [Quest2], [Quest3], [Quest4], [Quest5] WHERE ([QuestID] = @QuestID)">    <SelectParameters>        <asp:Parameter Name="QuestID" />    </SelectParameters> In my code I get the following error: "Cannot convert type 'int' to 'System.Data.DataView'...

Cannot implicitly convert type 'System.DBNull' to 'System.DateTime'
I'm using _StartDate = DBNull.Value;  _StartDate is datetime Somehow its not working when I set to dbnull.value Error 1 Cannot implicitly convert type 'System.DBNull' to 'System.DateTime'   i want to set to null or empty, how do i do that?  thanks.Its all about coding! Dear, the DateTime datatype cannot be null. that is why ur getting this kind of error what u can do is to set the default value for the DateTime variable that u have to the DateTime.MinValue. it will give u a date (1/1/0001) which for sure you can depend on. Happy codingHaissam Abdul MalakMCA...

Unable to cast object of type 'System.String' to type 'System.Data.DataRowView'
Hi, I am having this problem: Unable to cast object of type 'System.String' to type 'System.Data.DataRowView'I have two repeaters: One is for a list of terms and the other show the definition. What I am trying to do is, highlight the selected term.Here is the relevant code which has this error:private Color SetButtonBackColor(object dataItem){ Response.Write("<br />In SetButtonBackColor Function"); Response.Write("<br>dataItem in SetColor is: " +(string)((DataRowView)dataItem)["TermIndex"]); string _initial =  (string) ((DataRowView)dataItem)["TermIndex"]; &n...

Unable to cast object of type 'System.Object[]' to type 'System.Data.DataView'.
I am tring to retieve a single node from my BLL code which retrieve one instane of Repot object:DataView dv = (DataView)objBoutPrep.Select();I am getting error:Unable to cast object of type 'System.Object[]' to type 'System.Data.DataView'. The BLL code returns onle one object and not a list of objects.Please help Client code: <asp:ObjectDataSource ID="objBoutPrep" runat="server" SelectMethod="GetRByID" UpdateMethod="UpdateT" TypeName="MB.K.BLL.G.Report"> <SelectParameters> <asp:Query...

Unable to cast object of type 'System.IO.FileInfo' to type 'System.Data.DataRowView'.
This code below: Dim DomainVariable As String DomainVariable = Session("Domain")   If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem ThenDim FileRow As DataRowView = e.Item.DataItem Dim FileLink As HyperLink = e.Item.FindControl("FileHyperLink")Dim FileName As String = FileRow("Name")FileLink.NavigateUrl = String.Format("http://{0}/{1}", DomainVariable, FileName) FileLink.Text = FileRow("Name") End If IS GENERATING THIS ERROR............... Unable to cast object of type 'System.IO.Fil...

Unable to cast object of type 'System.Boolean' to type 'System.Data.SqlClient.SqlParameter'.
In my code this doesn't work:prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2I get the error:Unable to cast object of type 'System.Boolean' to type 'System.Data.SqlClient.SqlParameter'. But this does: prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int)prms(0).Value = 2Any reason why?  You code prms(0) = New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2 do evaluation: 1. if New SqlParameter("@QUERYTYPE", Data.SqlDbType.Int).value = 2, the result is Yes or No, 2. prms(0) =...

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

Cannot implicitly convert type 'System.Xml.XmlNode' to 'XmlNode' and 'XmlNode' does not contain a definition for 'AppendChild'
Hi,      XmlNode t = xmlDoc.SelectSingleNode("/NewDataSet/Table1/Template");//Cannot implicitly convert type 'System.Xml.XmlNode' to 'XmlNode'//        XmlText textNode1 = xmlDoc.CreateTextNode("hello");                       XmlElement ChildofTemplate = xmlDoc.CreateElement("ChildTemplate");//'XmlNode' does not contain a definition for 'AppendChild'// ...

Web resources about - Cannot implicitly convert type 'System.Data.DataTable' to 'System.Data.Dataset' - asp.net.sql-datasource

Resources last updated: 2/14/2016 11:42:34 PM