东软内部材料(四)asp等相关的教学案例 

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

软件大小: 20863 K
上传用户: rentianchou
关键词: asp 材料 教学案例
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				
				
				
				
				
				
				
				
				
				The .NET DataSet and OleDbDataAdapter Objects
				
				
				
				The .NET DataSet and OleDbDataAdapter Objects
				
				
				
				
				
				Connection string: 
				SELECT command: 
				+nbsp;
				
				
				
				
				
					void Page_Load(Object sender, EventArgs e)
					{
						// get connection string from ..\global\connect-strings.ascx user control
						string strConnect = ctlConnectStrings.OLEDBConnectionString;
						outConnect.InnerText = strConnect; // and display it
				
						// specify the SELECT statement to extract the data
						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
						DataSet objDataSet = new DataSet();
				
						try
						{
							// create a new Connection object using the connection string
							OleDbConnection objConnect = new OleDbConnection(strConnect);
				
							// create a new DataAdapter using the connection object and select statement
							OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(strSelect, objConnect);
				
							// fill the dataset with data from the DataAdapter object
							objDataAdapter.Fill(objDataSet, "Books");
						}
						catch (Exception objError)
						{
							// display error details
							outError.InnerHtml = "* Error while accessing data."
											+ objError.Message + "" + objError.Source;
							return;		//  and stop execution
						}
				
						// create a DataView object for the Books table in the DataSet
						DataView objDataView = new DataView(objDataSet.Tables["Books"]);
				
						// assign the DataView object to the DataGrid control
						dgrResult.DataSource = objDataView;
						dgrResult.DataBind();  // and bind (display) the data
				
					}
					
				
				
				
				
				
				
				
							

相关资源