1

これは私のコードです

    var s = from p in db.tblTotalFees
                where p.Class == ClassDropDownList.SelectedItem.Value && p.StudentID == Convert.ToInt32(StudentNameDropDownList.SelectedValue)
                select p;
        DataTable dt = new DataTable();

pをデータテーブルに変換してdtに保存するにはどうすればよいですか???

4

1 に答える 1

1

MSDN How to: Implement CopyToDataTable Where the Generic Type T Is Not a DataRowCopyToDataTable()で説明されている拡張メソッドを使用できます。使用法:

var selectedClass = ClassDropDownList.SelectedItem.Value;
int id = Convert.ToInt32(StudentNameDropDownList.SelectedValue);

var query = from p in db.tblTotalFees
            where p.Class ==  && selectedClass
                  p.StudentID == id
            select p;

DataTable dt = query.CopyToDataTable(); // here

または、純粋な ADO.NET を使用することもできます - SqlCommand を作成し、テーブルにSqlDataAdapterを入力します。

于 2013-04-19T12:37:16.603 に答える