GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  ASP.NET
Go To First  |  Previous Question  |  Next Question 
 ASP.NET  |  Question 15 of 164    Print  
can i assign datagrid.datasource = datareader
will it work?
will it fill my datagrid with the values

thankx in advance.
parikshit sehgal

  
Total Answers and Comments: 10 Last Update: January 29, 2008     Asked by: parikshit 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Mrityunjayan
 
Sivakesh is absolutely wrong. u can very well provide data reader as datasource. only thing is that u cannot do sorting and paging(paging can be done , but with difficulty)

Above answer was rated as good by the following members:
dainy_patel
October 19, 2005 00:31:05   #1  
hunaid mushtaq        

RE: can i assign datagrid.datasource = datareader
Yes
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
October 21, 2005 05:48:33   #2  
fire horse Member Since: October 2005   Contribution: 3    

RE: can i assign datagrid.datasource = datareader
Dim dTable AS new DataTable Dim qry AS String SELECT ItemNo ItemName ItemDescription FROM tblItem Dim sqlCommand AS new SqlCommand(qry sqlConn) sqlConn.Open ResultGrid.DataSource sqlCommand.ExecuteReader() ResultGrid.DataBind() sqlConn.Close
 
Is this answer useful? Yes | No
November 28, 2005 15:44:50   #3  
sivakesh        

RE: can i assign datagrid.datasource = datareader
no... You Cant... you can assig only dataSet or dataDable...
 
Is this answer useful? Yes | No
December 06, 2005 08:30:05   #4  
m_sanwal Member Since: December 2005   Contribution: 1    

RE: can i assign datagrid.datasource = datareader
Yes you can. Please check with datareader you will be find that it works.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
December 14, 2005 06:21:44   #5  
Mrityunjayan        

RE: can i assign datagrid.datasource = datareader
Sivakesh is absolutely wrong. u can very well provide data reader as datasource. only thing is that u cannot do sorting and paging(paging can be done but with difficulty)
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
January 02, 2006 05:02:17   #6  
meetsenthilbtech Member Since: January 2006   Contribution: 2    

RE: can i assign datagrid.datasource = datareader
We can bind datagrid to datareader.Sorting and paging also possible since we can able to sort the grid itself with out need of dataset or dataview.The only disadvantage is that it overcome the disconnected dataset concept when we using datareader.
 
Is this answer useful? Yes | No
February 17, 2006 00:03:07   #7  
bala_siva1979@yahoo.co.in        

RE: can i assign datagrid.datasource = datareader

Dim connString As String Server localhost;Database Northwind;Integrated Security SSPI
Dim sql As String SELECT * FROM Products

Dim conn As SqlConnection New SqlConnection(connString)
Dim command As SqlCommand New SqlCommand(sql conn)

Try
conn.Open()
Dim reader As SqlDataReader command.ExecuteReader()
Me.DataGrid1.DataSource reader
Me.DataGrid1.DataBind()
Catch ex As Exception
' Exception handling code goes here
Finally
conn.Close()
End Try


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 10, 2006 02:40:34   #8  
deb        

RE: can i assign datagrid.datasource = datareader

i dont think paging is possible by using datareader in datagrid........

we can bind data to datagrid using datareader in web application(asp.net) only ...........in windows application it is not possible...

regards

deb


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
January 19, 2008 03:19:52   #9  
SasiKarasi Member Since: January 2008   Contribution: 2    

RE: can i assign datagrid.datasource = datareaderwill it work?will it fill my datagrid with the valuesthankx in advance.parikshit sehgal
Yes You can assign DataReader as datasource to DataGrid. But datareader is read only so you can't modify the data.
Correct me if I am wrong.
-----------------------------------
Life is too short and so sweet.
(sasi . karasi @ gmail . com)

 
Is this answer useful? Yes | No
January 29, 2008 00:13:50   #10  
pallavipin Member Since: January 2008   Contribution: 2    

RE: can i assign datagrid.datasource = datareaderwill it work?will it fill my datagrid with the valuesthankx in advance.parikshit sehgal
please try this

//first create the columns to be displayed in the datagridview
MySqlConnection objcon new MySqlConnection(Give u r database conection here);

objcon.Open();

MySqlCommand objcmd new MySqlCommand();

objcmd.Connection objcon;

objcmd.CommandText
"select * from abc";

MySqlDataReader reader objcmd.ExecuteReader();

while (reader.Read())

{



dataGridView1.Rows.Add(reader.GetString(
"ColumnName").ToString());

}


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape