2013-11-03 29 views
0

我有2個表:碩士詳情記錄SQL查詢

  • Document(列DocNo, Doctype, DocTitle
  • Registration(列:RegNo, DocNo, RedDate, Location

對於表示我寫這個存儲過程數據:

CREATE Proc Show_Data_ByTitle 
    @Title nvarchar(20) 
AS 
    SELECT * FROM Document WHERE DocTitle = @Title; 

    SELECT * FROM Registration 
    WHERE DocNo IN (SELECT DocNo FROM Document WHERE DocTitle = @Title); 

現在我想笑w結果在gridview -asp.net page-

我該怎麼做?

+0

從哪張表格中顯示網格視圖,文檔或註冊數據? – Kuldeep

+0

他們兩個,在2個網格 – AComputer

回答

0

首先,我認爲你需要在你的SQL語句

SELECT * FROM 
Document INNER JOIN Registration 
ON Document.DocNo=Registration.DocNo 
Where [email protected] 

下一個內部聯接,如果你正在使用ADO.NET來解釋,你可能會想要的數據類專業類將數據存儲像

public class DocumentRegistration 
{ 
    public int DocNo {get; set;} 
    public string DocType {get; set;} 
    public string DocTitle {get; set;} 
    public int RegNo {get; set;} 
    public DateTime RedDate {get; set;} 
    public string Location {get; set;} 
} 

接下來,您可以使用ADO.NET數據進入你的類

List<DocumentRegistration> list= new List<DocumentRegistration>(); 
SqlConnection conn = new SqlConnection(); 
conn.ConnectionString="YourConnectionString" 
conn.Open(); 
SqlCommand cmd = new SqlCommand("Show_Data_ByTitle", conn); 
SqlCommand cmd = System.Data.CommandType.StoredProcedure; 
cmd.Parameters.Add(new SqlParameter("Title", "yourtitle")); 

SqlReader reader = cmd.ExecuteReader(); 
while(reader.Read()) 
{ 
    DocumentRegistration dr=new DocumentRegistration 
    { 
     DocNo = Convert.ToInt32(reader["DocId"]); 
     DocType = Convert.ToString(reader["DocType"]); 
     DocTitle = Convert.ToString(reader["DocTitle"]); 
     RedDate = Convert.ToDateTime(reader["RedDate"]); 
    } 

    list.Add(dr); 
} 

//put this code where you want to load the list like PageLoad() 
GridView1.DataSource=list; 
GridView1.Databind(); 

希望這會有所幫助

+0

我有2個網格一個文件和另一個註冊。 – AComputer

+0

對不起,我以爲你想要一個表中的數據。在這種情況下,您可以簡單地使用兩個類來代替數據並顯示它。 –