Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a asp.net project which needed to bind data with grid-view from two different database

How can i do this?
Posted

Get the data from two databases, put that into a single Business model object you might have and bind it to the grid.
 
Share this answer
 
If your data are the same format you should take data from your databases and then kept in two data tables.After that combine these data in another datatable and bind gridview.

Best regard,
Theingi win
 
Share this answer
 
1.Add two connection String in web config
2.Call two connection in code page.
3.so for u will get two dataset
4.Use Merge function

Now u will get the two table from different database in a single page.
C#
<add name="Constring" connectionstring="Data Source=......" providername="System.Data.OracleClient" />

<add name="Constringnew" connectionstring="Data Source=......" providername="System.Data.OracleClient" />


In coding page
C#
String conn_user= System.Configuration.ConfigurationManager.ConnectionStrings["Constringnew"].ToString();
String conn = System.Configuration.ConfigurationManager.ConnectionStrings["Constring"].ToString();

C#
string query_login = "select * from Login";
        SqlConnection con_login = new SqlConnection(conn);
        SqlDataAdapter da_login = new SqlDataAdapter(query_login, con_login);
        DataSet ds_login = new DataSet();
        da_login.Fill(ds_login);

        string query_user= "select * from tbl_user";
        SqlConnection con_user = new SqlConnection(conn_user);
        SqlDataAdapter da_user = new SqlDataAdapter(query_user, con_user);
        DataSet ds_user = new DataSet();
        da_user.Fill(ds_user);

        ds_login.Merge(ds_user);
 
Share this answer
 
use linked server.. after linking the server, you can access them as in one database... follow the link to know more

http://msdn.microsoft.com/en-us/library/aa213778(v=sql.80).aspx[^]

http://msdn.microsoft.com/en-us/library/ms188279.aspx[^]
 
Share this answer
 
Comments
[no name] 16-Nov-11 2:38am    
Where did the op mention anything about having two database servers?
bigyan sahoo 25-Apr-14 9:38am    
These two systems are connected through LAN. But when I want to access them through their IP address the connection could not opened from the client system.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900