473,410 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

binding data to datagrid

in windows apllication, i want to select table's data and show it in datagrid
but i dont undertand how will i bind the data
is there any way to use datagrd view manager or something like this????
m confused!!!
Jul 9 '07 #1
8 3137
dip_developer
648 Expert 512MB
in windows apllication, i want to select table's data and show it in datagrid
but i dont undertand how will i bind the data
is there any way to use datagrd view manager or something like this????
m confused!!!
I have given you the answer in the Codeproject.com ASP.NET forum...........
Jul 9 '07 #2
I have given you the answer in the Codeproject.com ASP.NET forum...........
thank u but my prb is not yet solved...
Jul 9 '07 #3
dip_developer
648 Expert 512MB
thank u but my prb is not yet solved...
why???
where are u getting the problem...
please post your code if possible
Jul 9 '07 #4
why???
where are u getting the problem...
please post your code if possible
well! isnt there any need to use data reader??
well my code is

//connection as conn

strQuery = " SELECT * FROM table";
SqlCommand com1 = new SqlCommand(strQuery, conn);


DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter();

SqlDataReader dr = com1.ExecuteReader();

if (dr.Read())
{

da.Fill(ds,"table");


}

its not working i mean data is not displaying in the grid..and the exception that is shown is

"The SelectCommand property has not been initialized before calling 'Fill'."
(i asked u the same quest in codeproject.com...) and yea i tried doing it the exactly the same way u told but no rows returnd :(
Jul 9 '07 #5
dip_developer
648 Expert 512MB
well! isnt there any need to use data reader??
well my code is

//connection as conn

strQuery = " SELECT * FROM table";
SqlCommand com1 = new SqlCommand(strQuery, conn);


DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter();

SqlDataReader dr = com1.ExecuteReader();

if (dr.Read())
{

da.Fill(ds,"table");


}

its not working i mean data is not displaying in the grid..and the exception that is shown is

"The SelectCommand property has not been initialized before calling 'Fill'."
(i asked u the same quest in codeproject.com...) and yea i tried doing it the exactly the same way u told but no rows returnd :(


why are u using datareader and dataset simultaneously???
follow this...

the code is in vb.net...i think you will convert it to c# easily...otherwise tell me.....

Expand|Select|Wrap|Line Numbers
  1.  
  2. '1. Create a connection
  3. Dim myConnection as New SqlConnection(
  4. ConfigurationSettings.AppSettings("connectionString"))
  5. '2. Create the command object, passing in the SQL string
  6. Const strSQL as String = "SELECT * FROM myTable"
  7. Dim myCommand as New SqlCommand(strSQL, myConnection)
  8. 'Set the datagrid's datasource to the datareader and databind
  9. myConnection.Open()
  10. DataGrid1.DataSource = myCommand.ExecuteReader(
  11. CommandBehavior.CloseConnection)
  12. DataGrid1.DataBind()
  13.  
but keep in mind
A datareader is a read-only object. If you need to edit and update changes you need to use a dataset.
Jul 9 '07 #6
why are u using datareader and dataset simultaneously???
follow this...

the code is in vb.net...i think you will convert it to c# easily...otherwise tell me.....

Expand|Select|Wrap|Line Numbers
  1.  
  2. '1. Create a connection
  3. Dim myConnection as New SqlConnection(
  4. ConfigurationSettings.AppSettings("connectionString"))
  5. '2. Create the command object, passing in the SQL string
  6. Const strSQL as String = "SELECT * FROM myTable"
  7. Dim myCommand as New SqlCommand(strSQL, myConnection)
  8. 'Set the datagrid's datasource to the datareader and databind
  9. myConnection.Open()
  10. DataGrid1.DataSource = myCommand.ExecuteReader(
  11. CommandBehavior.CloseConnection)
  12. DataGrid1.DataBind()
  13.  
but keep in mind
A datareader is a read-only object. If you need to edit and update changes you need to use a dataset.
hmmmm but as i told i m working in windows application and it doesnt support databind option
is there any replacement or any directives/namespaces to include?
and what if i want to update records using dataset?
Jul 9 '07 #7
dip_developer
648 Expert 512MB
hmmmm but as i told i m working in windows application and it doesnt support databind option
is there any replacement or any directives/namespaces to include?
and what if i want to update records using dataset?
sorry shamaila I have forgotten that yours a windows application...
then you have to make a datatable with that datareader and bind it to the datagrid....

i dont see any other option for you..
Jul 9 '07 #8
sorry shamaila I have forgotten that yours a windows application...
then you have to make a datatable with that datareader and bind it to the datagrid....

i dont see any other option for you..
thx i'll try it now!!
Jul 10 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
0
by: David Steward | last post by:
When looking at the help files for datagrid I see a lot of information for how to data bind the datagrid to a database. The help information mentions that data binding can be done also to an...
0
by: Dave | last post by:
The question I have is how to -=> Effectively <=- and -=> Efficently <=- bind a DataGrid to a 1 deep organizational chart, where "R" would be a row of data and 1..N would be the columns of the row....
1
by: reiks | last post by:
Do we any computed column for the datagrid? Do we any expression property for the datagrid columns? My requirement is I ought to bind the following expression at design time if(au_lname=="",'...
2
by: Andrew Robinson | last post by:
Is there any way to accomplish two way data binding in a Details View with a DataSet or DataTable as the DataSource. All I want is to get an updated DataSet or DataTable back from the...
5
by: Brad Shook | last post by:
I am trying to bind one column of a datagrid to a seperate textbox and the rest of the fields to a datagrid. the comments are too large to fit in a datagrid so I created a textbox below the...
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
1
by: Stephen Barrett | last post by:
I have an application that was originally built with ASP.Net 1.1. We finally got permission to migrate to 2.0. Due to time constraints we migrated the web projects to 2.0 web application...
0
by: sampalmer21 | last post by:
Using visual studio 2005, there are built in mechanisms for data binding such as using the DataGrid control and connecting it to a data source which would then produce a TableAdapter object and a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.