DataSource Controls :: How To Read Data From The SqlDataReader .
Apr 18, 2010how to read data from the sqlDataReader .
sqlDataReader sdr = sql_comm.executeDataReader();
if(sdr.hasRows)
{
while(sdr.read)
i=0
[code]...
how to read data from the sqlDataReader .
sqlDataReader sdr = sql_comm.executeDataReader();
if(sdr.hasRows)
{
while(sdr.read)
i=0
[code]...
In SQL Server 2008 bit is like boolean (true/false), but I tried to read the bit value (0 or 1) and got error. How can I read it?
[Code]....
[Code]....
My question is how do i use SqlDataReader to read the last row added to a table getting the contents of a column and storing it as a c# varaible
I have a SQL Server 2008 database and I am working on it in the backend. I am working on asp.net/C#
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//how do I read strings here????
}
I know that the reader has values. My SQL command is to select just 1 column from a table. The column contains strings ONLY. I want to read the strings (rows) in the reader one by one. How do I do this?
When I query for only one record/row, sqldatareader is giving correct result but when i query for multiple rows, its giving error on the client side. below is my code.
[code]....
I am trying to run a stored proc from this function. When I run it thorugh the debugger I can see that myReader.HasRows = true and myReader.FieldCount =14.
But the control does not go in the loop while (myReader.Read()) where I am trying to read Version field returned by the stored proc.
[Code]....
I'm trying to convert some code from VB to C# on a site i'm working on and can't seem to get the arraylist to function properly.
Here is what we currently have in the codebehind:
[Code]....
Which we then call from the page using:
[Code]....
I want to convert this to C# as the rest of the code on the new site is in C# and I'm having problems with the ArrayList. I've got the other parts of the code all converted fine it's just the GetContent Function that isn't working right. Here's what I have:
[Code]....
I got an error on the "objSDR.Item" part of the code saying "SqlDataReader doesn't have definition for Item" and so if I changed this to the code above. Only problem now is I can't call this from the page using the code below as there is no "Item" in the GetContent Function any more
[Code]....
[Code]....
Why SqlDataReader Class object is not created by "new" Operator.
Is it not possible to create the object like below
SqlDataReader dr=new SqlDataReader();
dr=cmd.ExecuteReader();
Why the constructor of the SqlDataReader class is internal?
When I am using SqlDataReader class on that time without creating instance of the SqlDataReader Class I m using Command.ExecuteReader() Method. Why We not create the object of the SqlDataReader Class by using " new " Operator.We use like below:
SqlDataReader dr=cmd.ExecuteReader();
Why not we use this class like below:
SqlDataReader dr=new SqlDataReader();
dr=cmd.ExecuteReader();
When using the DataTable.Load(SQLDataReader) method, if the datatable is a property of a class, the set method is not called to populate the object. For example...
MySQLDataReader = command.ExecuteReader();
if (MySQLDataReader.HasRows)
myObjDataTable.Load(MySQLDataReader); -- The result of this will be 0 rows returned. The "Set" method of the object is never called.
I have several methods where I return a SqlDataReader to populate Gridviews, Listview, etc. I get random "Timeout expired" errors regarding connection pooling, so I decided to add using{} to my methods. The lack of using is a carry over from my more beginner days.Below I included the before and after code. The after code always gives me the "Invalid attempt to call FieldCount when reader is closed" error. I have tried various combination of using{}, but ALL result in the same error.What am I doing wrong? Also, from the code below what is the best way to structure this code to ensure no connection leakage?Before:
[Code]....
After:
[Code]....
i'm tring to read data from a sql DB, where is email == mystring - then display its name here is the code:
string mystring;
mystring = "email@email.com";//"Welcome " + System.Convert.ToString(Session["user"]);
generalTableTableAdapters.kurtula_generalTableAdapter generals = new
generalTableTableAdapters.kurtula_generalTableAdapter();
generalTable.kurtula_generalDataTable genaraltab = generals.Getgeneral();
foreach (DataRow row in genaraltab.Rows)
{
if (Convert.ToString(row["email"])== user)
{
Label1.Text = System.Convert.ToString(row["name"]);
}
}
as you can see I'm a table adapter but is giving me the following error: i realy dont know what this error means - though i did a simular action using access DB (and it did work), where i had to user the following: using System.Data.OleDb; now because im using SQL DB im using: using System.Data.SqlClient; //sql server
I am running the code below to read a sql table and populate the values into a list. This works on the first run through, but after the data has been processed, and the process then re runs, if the sql table has been modified externally, the read of the records does not change. I imagine it is being cached somwhere but as I re dim the dData variable, shouldn't it all be dropped and run afresh?
[Code]....
Whats the best way to read data from cvs file
View 2 Repliesi am trying to read data of from a sql database
the code that im using is as follows:
[Code]....
as you can see, im using table adapters - though when i run the page, it throughs me the following error, which i'm finding hard to understand
for my last project, i had to use the exact code, but at the time, i was using an access DB and now i'm uning sql D|B
the only difference from last time is that instead of using :
using System.Data.OleDb;
Now im using: using System.Data.SqlClient; //sql server
I know it is recommended to use a using statement with a sqldatareader, but I was wondering if it is necessary when you are setting the datasource of a control to a datasource directly. in some places in my code I do this.
using (SqlDataReader reader = getReader())
{
while (reader.Read())
{
// do stuff with data
}
}
when binding to a control I do this.
ddlCustomer.DataSource = getReader(); // get Reader returns a sqldataReader
ddlCustomer.DataBind();
In the second case, do I need to use a using statement. Do i have to first declare an SqlDataReader in a using statement, then set the DataSource to that object. Seems like more clutter in the code, so i was hoping binding to the SqlDataReader disploses of the SqlDataReader.
in ASP.net website C# code
example:
in SQL server, I have table TaxTable with column named TaxID, SalaryFrom like this:
TaxID SalaryFrom
1 1
2 2083.00
3 2500.00
4 3333.00
5 5000.00
6 7917.00
is there a way to store the values under salaryfrom column into an array?
note: In C# , Im using system.data.common.DbProviderFactories
this is so that I can read data from both sql server and mysql
I m uploading a text file. I want to read that text file line by line and I want to save that data into database if there are no errors in that text file. I have 5 different columns in database and I want to take those 5 columns data in the text file and insert into respective columns.
For this, which is the best way to do. Can we read and insert data into respective fields in no time.
i have some issue and i need read and upload (data) from excel file to dbgrid threw ASPX page am using network server 2003
View 1 RepliesI have a lot of members data to enter into the ASPNETDB database. How can I read this data from an Access data file and input into the SQL database. All data is for user Names and Password,
View 1 Repliesi'm quite new to asp.net and have been working on a simple way for users to send messages to each other....
the messages work fine, users can send and reply, however, i want a way to tell the users when they have a message and how many...
how to do this in simple terms and supply vb code if possible.
I have an object datasource which is using Business object as a myconnection
The method i have defined under myconnection is
Publicstatic
DataTable getfn(String dtype,
String did,
String dprefix,
String dname)
{
datable table = new datatable(); then declared stored proceedure and defined parameters and assighned values
In the stored proceedure it has a query like select column1,coloumn2,coloumn3 As Call from table where
I need to take data from Call and display it to the gridview through object datasource .
I am using vs2008, Sqlserver2008.
my table: PostGL having data like thi
AutoIdx TxDate Id AccountLink Description Debit Credit
3 2010-01-22 JL 2 bcb 0 35.09
5 2010-01-28 JL 2 g 3.51 0
select AutoIdx,TxDate,Id,AccountLink,Description,Debit,Credit,(Debit-Credit) as Actual from PostGL where Id='JL' and AccountLink=2
AutoIdx TxDate Id AccountLink Description Debit Credit Actual
3 2010-01-22 JL 2 bcb 0 35.09 -35.09
5 2010-01-28 JL 2 g 3.51 0 3.51
I am trying in view like this
declare @cnt int
declare @i int
set @budget=20
set @cnt= (select COUNT(*) from PostGL where AccountLink=2 )
set @i=1
WHILE (@i<=@cnt )
BEGIN
set @tdebit=??
END
I am taking count the no of rows having AccountLink=2
I need to read all debit,credit and add all debit into totaldebit,all credit into totalcredit independently from table.
then i need to show the totaldiff as Actual.
i need ....totaldiff=totaldebit-totalcredit
how to convert sqldatareader to List
View 2 RepliesI need to be able to Page in my Datalist. As you can see from the code below I'm using a SqlDataReader to populate my Datalist.
[Code]....