您好:如下範例
DataSourceSelectArguments 的用途,他又沒有做任何arg設定?
一定要設嗎?
另外,
dv = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
'-- 執行 Sct的動作,從資料庫裡面獲得資料。
設定Empty用途?
謝謝!
Dim args As New DataSourceSelectArguments
'== DataSourceSelectArguments 提供一項機制,讓資料繫結控制項於擷取資料時,用來向資料來源控制項要求資料相關的作業。
Dim I_DR As IDataReader = CType(SqlDataSource1.Select(args), IDataReader)
Sub X()
Dim SqlDataSource1 As New SqlDataSource
SqlDataSource1.ConnectionString = WebConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString
SqlDataSource1.SelectParameters.Add("id", TextBox1.Text) '--取得資料
'SqlDataSource1.SelectParameters("id").DefaultValue = 2
SqlDataSource1.SelectCommand = "SELECT [id], [test_time], [title], [summary], [article], [author] FROM [test] WHERE ([id] = @id)"
SqlDataSource1.DataSourceMode = SqlDataSourceMode.DataSet
'== 如果 DataSourceMode 屬性設為 DataSet 值,則 Select 方法會傳回 DataView 物件。
Dim dv As DataView
dv = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView) '
'-- 執行 Select的動作,從資料庫裡面獲得資料。
'== 重 點!!==
GridView1.DataSource = dv
GridView1.DataBind()
'SqlDataSource1.Dispose()
End Sub