dataaccess.cs

来自「C#.net web developer s guide, c#网站开发者指南」· CS 代码 · 共 41 行

CS
41
字号
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;


namespace simpleCart.components
{
	/// <summary>
	/// This Class is used for all interactions with the data source
	/// </summary>
	public class dataaccess
	{
		private string connection = "Persist Security Info=False;User ID=sa; password=password; Initial Catalog=shopDb;Data Source=MAUNAKEA";
		
		/// <summary>
		/// getAllBooks connects to the SQL database and executes the stored procedure "GetAllBooks"
		/// </summary>
		/// <returns>DataSet containing the DataTable "Books"</returns>
		public DataSet getAllBooks()
		{
			// shopDb string "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa; password= password; Initial Catalog=shopDb;Data Source=MAUNALANI" ;
				
			SqlConnection conn = new SqlConnection ( this.connection ) ;
			
			conn.Open ( ) ;
			SqlCommand  cmd = new SqlCommand ( "GetAllBooks" , conn ) ;
			cmd.CommandType = CommandType.StoredProcedure;

			SqlDataAdapter da = new SqlDataAdapter (cmd) ;
			DataSet ds = new DataSet ( ) ;
			da.Fill ( ds , "Books" ) ;
			conn.Close();
				
			return ds;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?