filmov
tv
Part 1 How to retrieve data from different databases in asp net

Показать описание
If you are a foodie like me, I am sure you will enjoy the recipes on my friend's YouTube channel. If you find them useful, please subscribe and share to support her. She's really good at what she does.
Link for all dot net and sql server video tutorial playlists
Link for slides, code samples and text version of the video
Several of our youtube channel subscribers faced this question in a dot net written test.
We have 2 databases
1. USADB - Contains Employees table that stores only US Employees
2. UKDB - Contains Employees table that stores only UK Employees
Add a webform to the project. Drag and drop a GridView control on the webform. Copy and paste the following code in the code-behind file.
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Demo
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string USADBCS = ConfigurationManager.ConnectionStrings["USADB"].ConnectionString;
string UKDBCS = ConfigurationManager.ConnectionStrings["UKDB"].ConnectionString;
SqlConnection con = new SqlConnection(USADBCS);
SqlDataAdapter da = new SqlDataAdapter("select * from Employees", con);
DataSet ds1 = new DataSet();
da.Fill(ds1);
con = new SqlConnection(UKDBCS);
da.SelectCommand.Connection = con;
DataSet ds2 = new DataSet();
da.Fill(ds2);
ds1.Merge(ds2);
Gridview1.DataSource = ds1;
Gridview1.DataBind();
}
}
}
Link for all dot net and sql server video tutorial playlists
Link for slides, code samples and text version of the video
Several of our youtube channel subscribers faced this question in a dot net written test.
We have 2 databases
1. USADB - Contains Employees table that stores only US Employees
2. UKDB - Contains Employees table that stores only UK Employees
Add a webform to the project. Drag and drop a GridView control on the webform. Copy and paste the following code in the code-behind file.
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Demo
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string USADBCS = ConfigurationManager.ConnectionStrings["USADB"].ConnectionString;
string UKDBCS = ConfigurationManager.ConnectionStrings["UKDB"].ConnectionString;
SqlConnection con = new SqlConnection(USADBCS);
SqlDataAdapter da = new SqlDataAdapter("select * from Employees", con);
DataSet ds1 = new DataSet();
da.Fill(ds1);
con = new SqlConnection(UKDBCS);
da.SelectCommand.Connection = con;
DataSet ds2 = new DataSet();
da.Fill(ds2);
ds1.Merge(ds2);
Gridview1.DataSource = ds1;
Gridview1.DataBind();
}
}
}
Комментарии