473,769 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to fill the datagrid with a table

2 New Member
I have a sql server table and i want to read it in the datagrid view of C# .Net.
I think it is easy to do it. but i m not able to show any output in the datagrid...
here is my code.please guide me.where i m wrong..

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11. namespace grid
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.             DataGrid dataGrid1;
  23.             dataGrid1 = new DataGrid();
  24.  
  25.             string strConn, strSQL;
  26.             strConn = "server=ABC,Database=test;user id = sa;password=manager;Trusted_Connection=Yes";
  27.             strSQL = "select * from info";
  28.  
  29.             SqlDataAdapter da = new SqlDataAdapter(strSQL, strConn);
  30.             DataSet ds = new DataSet();
  31.             da.Fill(ds, "information");
  32.  
  33.             dataGrid1.DataMember = "info";
  34.             dataGrid1.DataSource = ds;
  35.  
  36.         }      
  37.  
  38.     }
  39. }
Nov 10 '08 #1
3 1193
kenobewan
4,871 Recognized Expert Specialist
Try datagrid1.datab ind(); and report back.
Nov 10 '08 #2
krungkrung
18 New Member
Hi!

I think, using the last code, dataGrid1.DataS ource = ds, you are refencing the whole dataset and not the specific table of the dataset which you named "information".. .maybe thats the reason why your datagridview doesnt know which particular records to show....

you may try: dataGrid1.DataS ource = ds.Tables("info rmation");

NOTE: information is the name of table you created in dataset during fill method execution of dataadapter [da.Fill(ds, "informatio n");]


hope this helps...cheers (",)
Nov 12 '08 #3
ruchikapali
4 New Member
HI!!!

use

datagrid1.datas ource=ds.tables["informatio n"];
datagrid1.datab ind();
Nov 28 '08 #4

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

Similar topics

4
1606
by: Mervin Williams | last post by:
I have several tables involved in my application, but the two in question here are the company and address tables. The company table has business_address_id and mailing_address_id columns, which are both foreign keys to the address table. So, the stored procedure to which my SelectCommand points to reads as: ALTER PROCEDURE dbo.CompanyInfoByCompanyID ( @companyid int
6
1622
by: JeffB | last post by:
I have tried several different methods of getting a datagrid to fill with information. Below is the code I'm now using. When viewed in the browser and the text box filled with a parameter value (i.e. CA for Calif), the datagrids header is displayed when the button is clicked, but no data is displayed. I used SQL Profiler and can see that the query comes across with the parameter, and if I take that query string and use it exactly in Query...
4
3754
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure and username, password etc will be exactly the same for each server, the only thing that will change is the server name. Idealy I would like to get the server names from a seperate dataset so there could be any number of servers, allthough in...
0
1198
by: Marcin Podle¶ny | last post by:
Hello! I use DataGrid which displays data in several columns. Number of columns depends on user prefferences (I mean: this is still the same query filling datatable but I use "DataTable.Columns(i).ColumnMapping = MappingType.Hidden" to hide columns which should be hidden). So, the code I use every time to fill DataTable and display data in DataGrid looks like: Private Sub xxxxx(...) Dim firstTime as Boolean = true
4
3292
by: jaYPee | last post by:
I have already done some code to fill the datagrid. my problem is that the fill method is too slow after executing my code. here is the scenario. i have a parent/child form. all is datagrid. one datagrid is a parent and the other is a child. now when i finish encoding data from the first datagrid (which is the parent) i have to click the check box button on that grid and fill the 2nd grid w/ the data from the other table base on the...
4
4533
by: jaYPee | last post by:
I have 1 dataset called "dataset1" that contains 2 tables called "course" and "courseload". in my form i have a datagrid. the datasource of this datagrid is "dataset1" and the datamember is "courseload". here's the fields of every table in my dataset. "Course" table CourseID
2
1635
by: Brett | last post by:
I have the following code in VS Studio .NET 2005 beta: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.DataAdapter1.Fill(DataSet1) End Sub Where a database connection has been made during design time and I can preview data. The above line gives a "specified method is not supported
10
13319
by: Rich | last post by:
I have a stored procedure on Sql Server2k. I can fill a data table which I can append to a dataset using an ADODB recordset object which gets populated from a command object that runs the sp. I was hoping to use a DataAdapter. But I think the data adapter only uses select statements. I could write the sp in my vb.net app, but the sp references UDF's I wrote in the Sql Sever. I will guess that I will need to stick with the ADODB recordset...
2
5227
by: MDB | last post by:
Hello All, I have a data grid that I fill using a dataset. The results of the query has around 15 columns and 500 rows (and growing). The reason I am using the datagrid is so the end users can auto sort and page so I would like to keep using the datagrid. My problem is that when I call DataAdapter.Fill, it takes a very long time and is even causing the web page to time out. Does anyone know why the fill is taking so long (15-20 sec)...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9987
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9857
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8867
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.