EzDevInfo.com

dataset interview questions

Top dataset frequently asked interview questions

DataSet.WriteXml to string

I'm tring to get a string from a DataSet without using GetXml. I'm using WriteXml, instead. How to use it to get a string? Thanks


Source: (StackOverflow)

R mtcars dataset, meaning of "vs" variable?

What does the "vs" variable mean in the "mtcars" dataset in R? The helpfile says it means "V/S" but that is not enlightening.

Commands:

data(mtcars)
head(mtcars)
?mtcars

Source: (StackOverflow)

Advertisements

How to delete the first row of a dataframe in R?

I have a dataset with 11 columns with over a 1000 rows each. The columns were labeled V1, V2, V11, etc.. I replaced the names with something more useful to me using the "c" command. I didn't realize that row 1 also contained labels for each column and my actual data starts on row 2.

Is there a way to delete row 1 and decrement?


Source: (StackOverflow)

Datasets for Running Statistical Analysis on [closed]

What datasets exist out on the internet that I can run statistical analysis on?


Source: (StackOverflow)

ClassCastException with ListView when executing notifyDataSetChanged

I have added a view to the header of listVivew,

    View TopSearch =  (View) View.inflate(this, R.layout.search, null);
    lv.addHeaderView(TopSearch, null, false);

And everything is fine until I try to execute (when data changes)

adapter.notifyDataSetChanged();

That always crash my application giving me following error:

> java.lang.ClassCastException: android.widget.HeaderViewListAdapter

If I remove header view then there is no error. Any suggestions? Thanks.


Source: (StackOverflow)

Datatable vs Dataset

I currently use a DataTable to get results from a database which I can use in my code.

However, many example on the web show using a DataSet instead and accessing the table(s) through the collections method.

Is there any advantage, performance wise or otherwise, of using DataSets or DataTables as a storage method for SQL results?


Source: (StackOverflow)

Nullable types in strongly-typed datatables/datasets - workarounds?

Strongly-typed DataTables support "nullable" field types, except that the designer will not allow you change the setting to "allow nulls" for any value type fields. (ie: String types allow nullable, but int's do not).

The workaround is to call IsMyFieldNull() any time you want to get Myfield. If you access MyField when it does contain a null, it throws an eception.

This is a massive headache, in addition to causing many runtime bugs when a null showing up can cause your app to crash. I've complained to microsoft for years about this, yet every new release of visual studio still does not allow nullable value types to be used.

My question: Anyone know of a fancy extension method(s) that could be used to work around this major shortcoming?


Source: (StackOverflow)

How can you name the Dataset's Tables you return in a stored proc?

I've got the following stored procedure

Create procedure psfoo ()
AS
select * from tbA
select * from tbB

I'm then accessing the data this way :

     Sql Command mySqlCommand = new SqlCommand("psfoo" , DbConnection)
     DataSet ds = new DataSet();
     mySqlCommand.CommandType = CommandType.StoredProcedure;
     SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
     mySqlDataAdapter.SelectCommand = mySqlCommand;
     mySqlDataAdapter.Fill(ds);

Now, when I want to access my tables, I have to do this :

     DataTable datatableA = ds.Tables[0];
     DataTable datatableB = ds.Tables[1];

the dataset Tables property also got an accessor by string (instead of int).

Is it possible so specify the name of the tables in the SQL code, so that I can instead write this :

     DataTable datatableA = ds.Tables["NametbA"];
     DataTable datatableB = ds.Tables["NametbB"];

I'm using SQL server 2008, if that makes a difference.


Source: (StackOverflow)

Copy DataTable from one DataSet to another

I'm trying to add to a new DataSet X a DataTable that is inside of a different DataSet Y. If I add it directly, I get the following error:

DataTable already belongs to another DataSet.

Do I have to clone the DataTable and import all the rows to it and then add the new DataTable to the new DataSet? Is there a better/easy way to do it?


Source: (StackOverflow)

Convert DataSet to List

Here is my c# code

Employee objEmp = new Employee();
List<Employee> empList = new List<Employee>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
    empList.Add(new Employee { Name = Convert.ToString(dr["Name"]), Age = Convert.ToInt32(dr["Age"]) });
}

It uses a loop to create a List from a dataset.Is there any direct method or shorter method or one line code to convert dataset to list


Source: (StackOverflow)

c# (WinForms-App) export DataSet to Excel

I need a solution to export a dataset to an excel file without any asp code (HttpResonpsne...) but i did not find a good example to do this...

Best thanks in advance


Source: (StackOverflow)

Select method in List Collection

I have an asp.net application, and now I am using datasets for data manipulation. I recently started to convert this dataset to a List collection. But, in some places it doesn't work. One is that in my old version I am using datarow[] drow = dataset.datatable.select(searchcriteria). But in the List collection there is no method available for finding particular values. Is there any way for me to select some values according with my search criteria? I want to know if this is possible. Please help me.


Source: (StackOverflow)

Sort column names of a dataframe

This is possibly a simple question, but I do not know how to order columns alphabetically.

test = data.frame(C=c(0,2,4, 7, 8), A=c(4,2,4, 7, 8), B=c(1, 3, 8,3,2))

 C A B
1 0 4 1
2 2 2 3
3 4 4 8
4 7 7 3
5 8 8 2

I like to get the dataset ordered by the column names alphabetically:

 A B C
1 4 1 0
2 2 3 2
3 4 8 4
4 7 3 7
5 8 2 8

For others I want my own defined order:

 B A C
1 4 1 0
2 2 3 2
3 4 8 4
4 7 3 7
5 8 2 8

Please note that my datasets are huge, with 10000 variables. So the process needs to be more automated.


Source: (StackOverflow)

Direct method from SQL command text to DataSet

What is the most direct route to get a DataSet if I have a sql command?

string sqlCommand = "SELECT * FROM TABLE";
string connectionString = "blahblah";

DataSet = GetDataSet(sqlCommand,connectionString);

GetDataSet()
{
   //...?
}

I started with SqlConnection and SqlCommand, but the closest thing I see in the API is SqlCommand.ExecuteReader(). With this method, I'll need to get a SqlDataReader and then convert this to a DataSet manually. I figure there is a more direct route to accomplish the task.

If easier, a DataTable will also fit my goal.


Source: (StackOverflow)

How to test if a DataSet is empty?

I'm modifying someone else's code where a query is performed using the following:

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlString, sqlConn);
da.Fill(ds);

How can I tell if the DataSet is empty (i.e. no results were returned)?


Source: (StackOverflow)