473,322 Members | 1,523 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,322 software developers and data experts.

fill dataadpter with more then one table

i want to fill dataadapter with more then one table what will be the syntax for it and binding more then one datamembers(tables) with grid
Jul 11 '07 #1
3 1322
i want to fill dataadapter with more then one table what will be the syntax for it and binding more then one datamembers(tables) with grid
well leave it i did it....
Jul 11 '07 #2
dip_developer
648 Expert 512MB
i want to fill dataadapter with more then one table what will be the syntax for it and binding more then one datamembers(tables) with grid
dataadapter cant be filled with table........please get the clear concept of ADO.NET by reading a good book or article.....
dataadapter is used to fill dataset which can have more than one table.

whenever you want to bind a grid with a dataset you have to specify the tablename of that particular dataset which will be a single table.

you can have a sql query where you can merge data from more than one table and fill a dataset with those records and further bind grid with that dataset.

but if you want to show record from two different tables separately then you need two different datasets.here you can merge two datasets and can show record of two different tables.but
keep in mind that if you want to merge two dataset then two tables of two different datasets should have the same schema
Follow the code..........

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub BindGrid() 
  3.      Dim myConnection as New SqlConnection (strConn) 
  4.  
  5.      Dim DS1 As DataSet 
  6.      Dim DS1 As DataSet 
  7.      Dim MyCommand As SqlDataAdapter 
  8.  
  9.      MyCommand = new SqlDataAdapter("exec s_get_table1", MyConnection) 
  10.      DS1 = new DataSet() 
  11.      MyCommand.Fill(DS1, "MyTable") 
  12.  
  13.      MyCommand = new SqlDataAdapter("exec s_get_table2", MyConnection) 
  14.      DS2 = new DataSet() 
  15.      MyCommand.Fill(DS2, "MyTable") 
  16.  
  17. 'The table name for both datasets are the same. 
  18. 'Also the data type and column name for both tables are the same. 
  19.  
  20.      ds1.merge(ds2) 
  21.  
  22.      MyDataGrid.DataSource=DS1.tables(0).DefaultView 
  23.      MyDataGrid.DataBind() 
  24. End Sub 
  25.  
Jul 11 '07 #3
dataadapter cant be filled with table........please get the clear concept of ADO.NET by reading a good book or article.....
dataadapter is used to fill dataset which can have more than one table.

whenever you want to bind a grid with a dataset you have to specify the tablename of that particular dataset which will be a single table.

you can have a sql query where you can merge data from more than one table and fill a dataset with those records and further bind grid with that dataset.

but if you want to show record from two different tables separately then you need two different datasets.here you can merge two datasets and can show record of two different tables.but
keep in mind that if you want to merge two dataset then two tables of two different datasets should have the same schema
Follow the code..........

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub BindGrid() 
  3.      Dim myConnection as New SqlConnection (strConn) 
  4.  
  5.      Dim DS1 As DataSet 
  6.      Dim DS1 As DataSet 
  7.      Dim MyCommand As SqlDataAdapter 
  8.  
  9.      MyCommand = new SqlDataAdapter("exec s_get_table1", MyConnection) 
  10.      DS1 = new DataSet() 
  11.      MyCommand.Fill(DS1, "MyTable") 
  12.  
  13.      MyCommand = new SqlDataAdapter("exec s_get_table2", MyConnection) 
  14.      DS2 = new DataSet() 
  15.      MyCommand.Fill(DS2, "MyTable") 
  16.  
  17. 'The table name for both datasets are the same. 
  18. 'Also the data type and column name for both tables are the same. 
  19.  
  20.      ds1.merge(ds2) 
  21.  
  22.      MyDataGrid.DataSource=DS1.tables(0).DefaultView 
  23.      MyDataGrid.DataBind() 
  24. End Sub 
  25.  
thank u...but my code worked i.e.:

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


DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(com1);
da.Fill(ds, "tbl1");
da.Fill(ds, "tbl2");

searchgrid.DataSource = ds;
searchgrid.DataMember = "tbl1";
searchgrid.DataMember = "tbl2";
Jul 11 '07 #4

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

Similar topics

4
by: Sherwood Botsford | last post by:
Table Markers ID (Primary Key) This&That PointClass (Combo box) Points Table PointClasses PointClass (primary key) Points (number) Description (Text)
3
by: JIM.H. | last post by:
If my dataset contains more than one table, and my sqlSelectCommand is only selecting from one table, does sqlDataAdapter1.Fill(dataSet11) know which table it should update?
2
by: Bernie Yaeger | last post by:
Is there any way to get into the internals of the data adapter fill method such that I could know its progress status? For example, using the fill method to load a 40,000 row table takes just a...
4
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...
1
by: Nikolay Petrov | last post by:
How to fill dataset with multiple tables and set their relaition? Can I get the relations from the SQL server? Also I would like to do it using stored procedures. TIA
4
by: Cindy H | last post by:
Hi I'm using an access database and vb.net I have been using the following type of function to get data from one table. This is working great - Public Shared Function GetAllLotsForSale()...
5
by: Monty M. | last post by:
Hello; I was wondering if anyone can assist me with this problem. Here are the tools I am using: Language: C# Database: MS SQL Server 2000 Application: Visual Studio 2005 1. I have a...
2
by: amr | last post by:
I use oracle developer tools(odt) to connect c# and oracle db ,i made a new connection,oracle command to select desirable data and new dataset by wizard way then i write in form load event ...
1
by: D | last post by:
I am experiencing slow response from my fill command. I am trying to open a database and one table and add data at some point. Is there a way to just open the table without all the data being read...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.