首先,我认为您需要在 SQL 语句中进行内部联接
SELECT * FROM
Document INNER JOIN Registration
ON Document.DocNo=Registration.DocNo
Where Document.DocTitle=@Title
接下来,如果您使用 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();
希望这可以帮助