Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The Select Statement picks fields from 2 databases : WHR WPAY


C#
SqlConnection connect = new SqlConnection();
connect.ConnectionString = ConfigurationManager.ConnectionStrings["WEBPAY"].ConnectionString;
connect.Open();

SqlDataAdapter da = new SqlDataAdapter(@"Select WHR.dbo.PAYMAST.IDNO ,WHR.dbo.PAYMAST.EMPNO,FNAME,
WHR.dbo.PAYMAST.LNAME,WHR.dbo.PAYMAST.DEPTNAME from WHR.dbo.PAYMAST
where WHR.dbo.PAYMAST.IDNO not in
(Select WPAY.dbo.Paycurrt.idno from WPAY.dbo.Paycurrt)", connect);

DataSet ds = new DataSet();
da.Fill(ds, "Paycurrt");

GridView1.DataSource = da;
GridView1.DataBind();

// lblstatus.Text = "First record successful";
connect.Close();

GridView1.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged1);

ERROR MESSAGE
Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.

In Configure DataSource I have the following.
The Test Query is ok.
SQL
SELECT IDNO, EMPNO, FNAME, LNAME, DEPTNAME FROM WHR.dbo.PAYMAST WHERE (IDNO NOT IN (SELECT IDNO FROM PAYCURRT))

Which I have tested and generates the Expected Output.

I want to populate the Gridview from the Page Load

What I have tried:

On going Development Challenge in C#
Posted
Updated 10-Dec-19 5:30am
v2

1 solution

Bind the grid view to the DataSet, not the DataAdapter

GridView1.DataSource = ds;
 
Share this answer
 

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