Code for VB.NET教程源码 很好的源码

源代码在线查看: simple-dataset-sql.aspx

软件大小: 1359 K
上传用户: a195767236
关键词: Code for NET 源码
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				
				
				
				
				
				
				
				
				The .NET DataSet and SqlDataAdapter Objects
				
				
				
				The .NET DataSet and SqlDataAdapter Objects
				
				
								
				
				Connection string: 
				SELECT command: 
				 
				
				
				
				
				
				Sub Page_Load()
				
				   'get connection string from ..\global\connect-strings.ascx user control
				   Dim strConnect As String
				   strConnect = ctlConnectStrings.SQLConnectionString
				   outConnect.innerText = strConnect 'and display it
				
				   'specify the SELECT statement to extract the data
				   Dim strSelect As String
				   strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '1861003%'"
				   outSelect.innerText = strSelect   'and display it
				
				   'declare a variable to hold a DataSet object
				   'note that we have to create it outside the Try..Catch block
				   'as this is a separate block and so is a different scope
				   Dim objDataSet As New DataSet()
				
				   Try
				
				      'create a new Connection object using the connection string
				      Dim objConnect As New SqlConnection(strConnect)
				
				      'create a new DataAdapter using the connection object and select statement
				      Dim objDataAdapter As New SqlDataAdapter(strSelect, objConnect)
				
				      'fill the dataset with data from the DataAdapter object
				      objDataAdapter.Fill(objDataSet, "Books")
				
				
				   Catch objError As Exception
				
				      'display error details
				      outError.innerHTML = "* Error while accessing data." _
				          & objError.Message & "" & objError.Source
				      Exit Sub  ' and stop execution
				
				   End Try
				
				   'create a DataView object for the Books table in the DataSet
				   Dim objDataView As New DataView(objDataSet.Tables("Books"))
				
				   'assign the DataView object to the DataGrid control
				   dgrResult.DataSource = objDataView
				   dgrResult.DataBind()   'and bind (display) the data
				
				End Sub
				
				
				
				
				
				
				
				
							

相关资源