logo
down
shadow

c# code returns System.Data.DataSet instead of Data itself?


c# code returns System.Data.DataSet instead of Data itself?

By : Alex
Date : October 21 2020, 08:10 AM
seems to work fine In your for loop , you are printing whole data set only. so it is supposed to print dataset.
You need to replace following -
code :
    Console.Write(a.Rezultate) 
    Console.WriteLine(row[column.ColumnName].ToString());  


Share : facebook icon twitter icon
Cannot implicitly convert type 'System.Data.SqlClient.SqlDataReader' to 'System.Data.DataSet'

Cannot implicitly convert type 'System.Data.SqlClient.SqlDataReader' to 'System.Data.DataSet'


By : Demaratus
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I'm doing a project in C# using 3 a tier architecture. I wrote the code to sort the records from SQL. But it doesn't return any values.
code :
public DataSet SortBank()
        {
            try
            {
                SqlCommand cmd = new SqlCommand("SortBankMaster", dal.con);
                cmd.Parameters.Add("@BankName", SqlDbType.NVarChar).Value = Bank_Name;
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adpt.Fill(ds); 
                return ds;                 
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Error	5: Cannot implicitly convert type 'System.Data.DataSet' to 'System.Data.SqlClient.SqlDataAdapter'

Error 5: Cannot implicitly convert type 'System.Data.DataSet' to 'System.Data.SqlClient.SqlDataAdapter'


By : shabbaKhan
Date : March 29 2020, 07:55 AM
I wish this help you Sorry for the noobiness here but I'm having an issue with the following SQL connection in C# asp.net , This line
code :
da_Logins = new DataSet(); 
ds_Logins = new DataSet(); 
How to convert WindowsInstaller.Record to System.Data.Dataset or Data Table (While reading MSI file) in C#

How to convert WindowsInstaller.Record to System.Data.Dataset or Data Table (While reading MSI file) in C#


By : Rebecca Stats
Date : March 29 2020, 07:55 AM
To fix this issue Here's similar logic using the interop types rather then the DTF types. As you can see it's a lot more work. It's also a lot more fragile since COM is involved instead of P/Invoke. Also, if you can eliminate the requirement to create an ADO.NET DataTable, DTF supports LINQ queries and databinding. In other words, I wrote this for fun only. I would NEVER use this method in real code.
code :
 public static DataTable ReadMsiPropertyTable(string msiFile, string tableName)
        {
            DataTable dataTable = new DataTable(tableName);
            Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
            Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(installerType);
            Database database = installer.OpenDatabase(msiFile, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);

            string sqlQuery = String.Format("SELECT * FROM {0}", tableName);
            View view = database.OpenView(sqlQuery);
            view.Execute(null);

            Record names = view.ColumnInfo[MsiColumnInfo.msiColumnInfoNames];
            Record types = view.ColumnInfo[MsiColumnInfo.msiColumnInfoTypes];
            Record row = view.Fetch();

            for (int index = 1; index < names.FieldCount+1; index++)
            {
                string columnName = names.get_StringData(index);
                string columnSpec = types.get_StringData(index);

                switch (columnSpec.Substring(0, 1).ToLower())
                {
                    case "s":
                        dataTable.Columns.Add(columnName, typeof(String));
                        break;

                    case "l":
                        dataTable.Columns.Add(columnName, typeof(String));
                        break;

                    case "i":
                        dataTable.Columns.Add(columnName, typeof(Int32));
                        break;

                    case "v":
                        dataTable.Columns.Add(columnName, typeof (Stream));
                        break;
                }
            }

            while (row != null)
            {
                DataRow dataRow = dataTable.NewRow();
                for (int index = 0; index < dataTable.Columns.Count; index++)
                {

                    if(dataTable.Columns[index].DataType == typeof(String))
                    {
                        dataRow[index] = row.StringData[index + 1];
                    }
                    else if(dataTable.Columns[index].DataType == typeof(Int32))
                    {
                        dataRow[index] = row.IntegerData[index + 1];
                    }
                    else if(dataTable.Columns[index].DataType == typeof(Stream))
                    {
                       // Insanity has it's limits. Not implemented.
                    }
                }
                dataTable.Rows.Add(dataRow);
                row = view.Fetch();
            }
            return dataTable;
        }
Epplus Export Error like this : 'System.Data.DataSet' the object type 'System.Data.DataTable' not taken in kind.

Epplus Export Error like this : 'System.Data.DataSet' the object type 'System.Data.DataTable' not taken in kind.


By : testsemut
Date : March 29 2020, 07:55 AM
help you fix your problem I think the casting from DataSet to DataTable is giving the error. You cannot cast DataSet to DataTable directly.
Use the code below to do that.
code :
BindingSource bs = (BindingSource)dataGridView1.DataSource; 
DataTable dt= (DataTable) bs.DataSource;

 ws.Cells["A1"].LoadFromDataTable(dt, true);
C#.NET Error: Unable to cast object of type 'System.Data.DataTable' to type 'System.Data.DataSet'

C#.NET Error: Unable to cast object of type 'System.Data.DataTable' to type 'System.Data.DataSet'


By : Prasad
Date : March 29 2020, 07:55 AM
around this issue I have an editable Gridview, its data is stored in an XML file, when I attempt to insert / update / delete data to/from the Gridview, I get the following error: , It's because you're setting the DataSource to a DataTable:
Related Posts Related Posts :
  • How do request a correct access token in ASP.NET Core for Azure AD to access Microsoft Graph
  • How to run a .NET Core console application on Linux
  • UI not updating for bound element
  • C# Odata v4 open type raw values
  • DocumentFormat.OpenXml Modify Creator Propery of Document
  • How to SetBasePath in ConfigurationBuilder in Core 2.0
  • ASP MVC5 public readonly variable changes value when it should not
  • How to conditionally select item from hashset with queryable linq?
  • Progress Bar C# not showing the real progress
  • Correct logic to reconnect in SignalR with HubConnection
  • ComboBox with two or more sections
  • .NET listbox to SQLite DB
  • C# Ninject binding from Dictionary<Type, Type>
  • asp.net mvc -view displaying real-time progress status
  • Getting reference to dependent in service with generic type
  • Implementing EqualityCompare vs overriding GetHashCode and Equals
  • C# Linq Find all indexes of item in List<int> within another List<int>
  • XML image how to display at data grid columns in c#.net
  • How to override Equals and GetHash of HashSet
  • Creating Windows authentication and SQL Server authentication in login form
  • How to interop with Azure Service Bus topics created by MassTransit using Rebus?
  • MVC 5 Google Calendar Integration
  • C# - Use parallel arrays to calculate cost of a phone call in GUI
  • Use a int in entire code
  • How to display newly added element at the top of StackPanel in WPF?
  • T4MVC is generating T4MVC.cs and T4MVC1.cs
  • Remove blur effect on certain controls inside UserControl
  • Sql Transcation Query to Linq Query in Wcf Rest Service
  • Setting AWS S3 credentials in C# app
  • does not contain in an ObservableCollection
  • App doesn't run it crashed directly after I started it
  • Is it possible in Entity Framework MVC application to run .sql scripts on a different database
  • Type Inference with Deconstruct tuple assignment extension methods
  • Setting up mock objects for EF dbcontext to test repository methods
  • Using C# in XSLT with MSXSL 6.0
  • Absolute positioning of UIElement in FlowDocument in WPF
  • Display debuggers not showing up in Visual Studio 2017
  • Discord.NET Users playing the same game
  • Azure function output API call to 3rd party service
  • Unable to determine the relationship represented by navigation property ASP.NET core 2.0 Entity Framework
  • Regex to find group of Regex inside a word
  • When calling a method, when to reference the class, and when to reference the object?
  • AmazonCloudWatchLogsClient async methods failing with no error
  • Create FileStream in memory instead of saving a physical file on disk
  • ViewBag data coming from ActionFilter is persisting in session even after database
  • ERROR: the name 'lvSubCategories' does not exist in the current context
  • Why datetime can't recognise the string?
  • Getting 500 error while requesting to webservice using Ajax AutoCompleteExtender
  • The property 'x' is not a navigation property of entity type 'y'
  • ASP.NET MVC - How to generate empty input boxes in loop when model is empty?
  • Need help writing regular expression
  • Add/remove buttons to a panel with an arraylist c#
  • Linq .Where(type = typeof(xxx)) comparison is always false
  • Using EF6 Code First without migrations to an existing db how do I specify column names of the many to many join table?
  • C# - Using Thread.Sleep precisely in a console application
  • Add item to a List<Tuple> inside another list
  • Double[,], inversion C#
  • Counting a string to ensure the input is within a min/max boundary
  • Assign invalidValue to Enum variable (why is this not throwing an Exception?)
  • Namespace or type specified in the project-level Imports 'System.Threading.Tasks' doesn't contain any public member or c
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org