C# - SqlDataAdapter.Fill(DataTable) Returns No Rows?

Feb 7, 2011

I am trying to use a SqlDataAdapter to fill a DataTable, which I use as a data source to a DataGrid. The query is fine, at least when I run it manually in SSMSE. When I do the fill operation, the table gets the right columns, but no rows. The most frustrating part of this is that the code is identical (with a different query) on a different page. I cannot post the query, but my initialization code looks like this:

SqlCommand areaDAC = new SqlCommand (areaQuery, connection);
areaDAC.Parameters.Add (new SqlParameter ("@param", System.Data.SqlDbType.NVarChar, 50));
m_areaDataAdapter = new SqlDataAdapter (areaDAC);

Then to use it:

m_areaDataAdapter.SelectCommand.Parameters["@param"].Value = "Filter Val";
DataTable table = new DataTable ();
m_areaDataAdapter.Fill (table);

At this point, table has the right number of columns and no rows. I know the parameters are being added correctly, I know that data exists for the given query.

Update (as provided by Nik in a comment):


View 4 Replies

Similar Messages:

DataSource Controls :: SqlDataAdapter.Fill(StartRecord,MaxRecords, DataTable)?

Jun 8, 2010

In am using following code for paging purpose in asp.net to reduce the load of reading all the records from the database.

SqlDataAdapter.Fill(StartRecord,MaxRecords, DataTable);

I want to know whether this code Get all data from data base and filter the records in application or just fetch the needed records only.

View 4 Replies

Forms Data Controls :: Populate Repeater From DataTable - Fill From Webservice Or SqlDataAdapter?

Feb 16, 2010

I am not clear when do I want to use a webservice over a sqlDataAdapter for dataRetrieval. I want to populate a repeater control which I have been doing from a dataTable that I fill from a sqlDataAdapter. Is there criteria when I would want to use a webservice to fill my dataTable?

View 3 Replies

DataSource Controls :: How To Add Rows To Datatable And Use Sqldataadapter Update Method

Jan 24, 2010

I'm trying to add new rows to a data table and then use the sqldataadapter update method bu fund some problems. First, I written this code:


Excuse me but the most part of variable are in italian, however I think it is possible to understand how does it work. If I execute this code I obtain this error:

System.InvalidOperationException: Update requires a valid InsertCommand when passed DataRow collection with new rows.

After this I added these lines of code just above the last line:

SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
adapter.InsertCommand = cb.GetInsertCommand;

and I obtained this error:

Cannot convert method group 'GetInsertCommand' to non-delegate type 'System.Data.SqlClient.SqlCommand'. Did you intend to invoke the method?

View 2 Replies

DataTable.Rows.Find Returns Null

Feb 13, 2010

I have a DataTable for which a PrimaryKey constraint has been set to be a combination of an integer column and a datetime column. When I try to 'Find' a row by saying,


I get a null value. iContainerIndex has been defined as an object array of size 2 with the integer ID and date values in it.

When I set a breakpoint in my code, I see that the very same values are present in the datatable.

If I try to execute, DataTable.Select() method with the integer column filter, I get a result - but returns no result when called with the date column filter.

What am I doing wrong here? The very same DateTime value is present in the datatable.

View 1 Replies

SQL Server :: Timeout When Calling SqlDataAdapter.Fill (DataSet)?

Sep 13, 2010

This issue has stumped me for a while. Hopefully someone here can give me some insight.

When my site runs the following code it works just fine 99% of the time.


The command is calling a SQL Server 2005 stored procedure that takes 20 parameters and returns 6 tables of about 5-50 rows each. The paramters are all NVARCHAR, INT, or BIT data types. Only one of the parameters is Input/Output. There is a total of about 100 rows returned. Normally this takes a fraction of a second, but for some queries, it times out after 30 seconds.

When I run the exact same query in the Management Studio query window it takes 1 second.

what I can do to get the same performance from .Net as I am getting from Management Studio?

View 6 Replies

SQL Server :: SqlDataAdapter Update Returns 0 Records?

Jan 25, 2011

using ASP.NET 2.0 SqlDataAdapter update returns 0 records. I have a simple application that stores Passenger's ticket info in a sql database.

when a user clicks "Create Reservation" I add a Passenger Information (name, destination, PNR) to dataset
and save dataset in ViewState.

Then when user clicks update, I pull the dataset from viewState and try to update database. The update is returning 0. what i am doing incorrectly?

protected void btn_CreateReservation_Click(object sender, EventArgs e)
DataRow dr ;
dr = dt.NewRow();
dr["Name"] = txtBox_Name.Text; dr["Destination"] = txtBox_Destination.Text;
dr["PNR"] = Convert.ToInt32(txtbox_PNR.Text); dt.Rows.Add(dr);
ViewState["MyTable"] = dsPassengers;


View 1 Replies

DataSource Controls :: Fill Data In SQLDataAdapter From Multiple Tables?

Jan 26, 2010

I'm using the following query as an SqlCommand:


It obviously doesn't work...what can I do? I cannot use the "Merge" method, because I am working with several tables in a single SELECT statment.

View 2 Replies

SQL Server :: Parsing An Array Read From An MS Database/'System.Data.SqlClient.SqlDataAdapter' Does Not Contain A Definition For 'Rows'...

Mar 23, 2011

I am getting this error:

CS1061: 'System.Data.SqlClient.SqlDataAdapter' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'System.Data.SqlClient.SqlDataAdapter' could be found.

Here is my code, what am I doing wrong?:


View 4 Replies

DataSource Controls :: How To Select Rows From A DataTable And Create A New ViewList With The Selected Rows Only, While ...

May 31, 2010

I have one big DataTable with X rows. I want to select Y rows from it and bind them to a new ViewList. While doing it, I want to delete these rows from the DataTable (Having X - Y rows).

What is the best and fast way to do it?

I don't know if it is better to create a new DataTable to have the Y and after that bind them to a ViewList or something else?

I'm also looking for example in code how to select/delete rows from DataTable.

View 1 Replies

ADO.NET :: Find Rows In One DataTable From Another DataTable And Remove Them

Sep 9, 2010

I have a DataTable of available time slots. I have another DataTable of reserved time slots. I need to remove from the list of available slots the ones that have been reserved. The blocks are in 15 minute increments, but one of my problems is that the reservation can be longer than 15 minutes. I've had some luck removing one or two, but not all of the required columns.

Here's my code (it doesn't work right now).


View 1 Replies

DataSource Controls :: How To Fill Datatable Using Linq To Sql

May 10, 2010

using linqs how to fill datatable using linq to sql in asp.net

i have one storedprocedure to select data from table

and one s.p for insert the data and one for update the data

how i use these s.p to insert and update the data using linq. to sql

I am gettin error in this code


View 1 Replies

ADO.NET :: Correct Way To Fill A DataTable With A TableAdapter Method?

Dec 1, 2010

I have a dataset with a table adapter that has several queries. I want to execute on of the queries and fill a data table but am having trouble with this operation. Am I invoking my table adapter incorrectly? See line 56.


View 2 Replies

C# - Fastest Way To Fill DataTable From LINQ Query Using DataContext?

Feb 10, 2011

I am trying to run a linq query but I need the result as a datatable as I am using that to store records from different queries in the same viewstate object.The 2 versions below compile, but return an empty set. The exact error is "Value cannot be null.Parameter name: source". (and yes I have checked there is data):

MyDatabaseDataContext db = new MyDatabaseDataContext(conn);
IEnumerable<DataRow> queryProjects =
(from DataRow p in db.STREAM_PROJECTs.AsEnumerable()


View 1 Replies

Crystal Reports :: Fill RDLC Report With DataTable?

Mar 11, 2011

I tried to use typed dataset with a simple query and i got the report working.

Now, i am trying to do is:

I made a class in a project. That class just contains a simple function with a select query. This query returns a datatable. I just want to use all the fields returned by the datatable in the report.

Is there any solution to this ? or my approach is wrong ?


View 1 Replies

DataTable Is Always Returns Empty Values?

Feb 17, 2011

I'm .NET newbie and I have to write function which executes stored procedure and return DataTable.

my SqlConnection is already initialized and while running in debugger I can see DataAdapter returns values, but my DataTable is empty.

public DataTable ExecStoredProcedure(String spName, String uId)
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(spName, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UnitIDList", uId);
SqlDataAdapter da = new SqlDataAdapter(cmd);
catch (SqlException ex)
throw new Exception(ex.StackTrace + ex.Message);.......

View 1 Replies

Forms Data Controls :: Programmatically Fill The 8 Using A Single Datatable?

Jan 26, 2011

Using C#, Visual Studio 2010

I have 8 drop downlists created in .aspx page.

I try to programmatically fill the 8 using a single datatable. Each dropdownlist has its own column in the datatable and is supposed to display only the column that corresponds to it. It does display the column it is supposed to however it also displays a number of empty slots equal to all the other columns combined.Here is the code can someone tell me why I get the empty slots?


View 3 Replies

Forms Data Controls :: Why DataTable Always Returns Null

Oct 7, 2010

Since I am not using a DataSourceId at the markup I am having to create my own Sorting handler. I found a sample on MSDN but the variable 'dataTable' always returns null why?


and here is how I am feeding the DataGrid:


View 2 Replies

Web Forms :: GridView - How To Fill The Blank Rows With Alternate Color

Dec 27, 2010

I am having a gridview with alternative color i have used AlternatingRowsDefaultCellStyle. however, if my grid is not fullyfilled, ie the grid view page size is 20 and i have only 10 records in that page then the alternate row color will not apply for blank rows. My question is, How can I fill the blank rows with alternate color as well.

Hope there is some solution without adding empty rows at the end of the datasoure which will create problems while sorting the grids.

View 11 Replies

Forms Data Controls :: Dataadapter.Fill() Or DataTable.Load(Datareader) Give The Best Performance

Jan 21, 2010

i'm developing a website to my office, i have a question related data loadinf performance related.

dataadapter.Fill() or dataTable.Load(Datareader) give the best performance in asp.net ??

View 6 Replies

DataSource Controls :: SQL Only Returns All The Rows Some Of The Time

Jan 15, 2010

Iam confronted with a really weird issue the like of which ive never seen before. I recently developed a web application using ASP.net and launched it for my company, during the bug testing stages everything seemed fine, but once it was actually in production i started getting these weird errors that all stem from it not retrieving the correct rows.

The issue is this, sometimes the queries sent to the back end only return a partial amount of the rows actualyl requested, so if a user has a page loaded thats suppose to return X number of rows, they can sometimes get X - Y number of rows, and upon refreshing the page they get X - Z number of rows, and refreshing the same exact page again they might get X number of rows they were initially suppose to see. I've never seen anything like this before so Iam stumped.

I consulted some of the old developers in the company I used to work for, for assistance but when explaining and showing the problem they too were very confused with the issue.

View 10 Replies

Web Forms :: Displaying Message If Dataset Returns 0 Rows

Jun 25, 2012

I have a function which returns dataset after execution of sql statements

If the dataset retruns rows than he data shld be dislayed in reporting services

Else display no rows avaliable

But currently even if there are no rows as per the given condition, the earlier data gets displayed

View 1 Replies

Forms Data Controls :: Database Query Returns 2 Rows But Repeater Only Shows 1?

Apr 12, 2010

here is my code:

My sql query is returning 2 rows by my repeater is only displaying 1.


View 3 Replies

C# - Sum Selected Rows In Datatable Only ?

Aug 11, 2010

I have a datatable which has an amount column & a status column.I want to sum only those rows who have status '1'. How to do this ?I am summing the column via datatable Compute method.

View 1 Replies

C# - Updating Rows In DataTable?

Nov 22, 2010

I'm trying to update fields in a DataTable. The field I'm trying to edit is a date, I need to format it.

foreach (DataRow row in dt.Rows)
string originalRow = row["Departure Date"].ToString(); //displays "01/01/2010 12:00:00 AM"
row["Departure Date"] = DateTime.Parse(row["Departure Date"].ToString()).ToString("MM/dd/yyyy");
string newRow = row["Departure Date"].ToString(); //also displays "01/01/2010 12:00:00 AM"

How come this isn't getting updated?

View 2 Replies

Copyrights 2005-15 www.BigResource.com, All rights reserved