質問

In Below image a View is showing in DataSources.

Data Source

In Below image Same DataSource is shown in Data Set Design View
DataSet

After drag and drop of Same DataSource on form as Grid DataMember property of same Grid is not showing the name in its list.
Data Members


Propertis of Grid
Grid Propery


Properties of Binding Source
enter image description here


Script of the View is

ALTER View [dbo].[V_CustomerBalance] as
SELECT M.Sales_id,
       M.Sales_date, 
       M.Customer_id, 
       M.Total_Weight, 
       M.Total_Amount, 
       M.Is_fully_paid, 
       SP.New_SrNo, 
       SP.Total_Amount_Paid,
       (M.Total_Amount - SP.Total_Amount_Paid) AS Due_Amount
  FROM SalesMasterTable AS M ,
       (SELECT P.Sales_id, 
               MAX(P.Sr_no) + 1 AS New_SrNo, 
               SUM(P.Amount_paid) AS Total_Amount_Paid
          FROM SalesPaymentTable AS P
         GROUP BY P.Sales_id
        HAVING MIN(P.Amount_due) > 0) AS SP 
 WHERE M.Sales_id = SP.Sales_id
GO


My problem is, should the view present in data source be present in data member as well.

I think its Yes. If not then why?

役に立ちましたか?

解決

Some times is simpler to go back to basics.

Firstly your data grid view should be using as its data source a binding source component.

The data member of the GridView should be empty with only the data source selected (to the binding source).

If you follow the steps below you will get a working copy of a grid view using a sql view.

  1. Create a new DataSet in the solution and add your View to it.
  2. Open the Form where your Grid resides.
  3. On the context menu for the dataset set the data source to the typed Dataset in your solution.

This should create three components on you form.

  1. DataSet Component.
  2. A BindingSource attached to your DataSet Component.
  3. A Custom Table Adapter that comes from you In Solution data set.

Your grid view will have its data source attached to the Binding source. The binding source DataSource will be set to the DataSet Component in the form and its DataMember will display the view name. The Gridview should not display anything on the DataMember property as it will be getting all the data and information from the binding source.

In your code your binging source data member property should be set to the view name.

I hope this helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top