reportdb.cs

来自「《ASP.NET 2.0 XML 高级编程(第3版)》 《ASP.NET 2.」· CS 代码 · 共 42 行

CS
42
字号
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using System.Web.Configuration;

namespace ShoppingAssistantLib
{
	public class ReportDB
	{		
		/// <summary>
		/// Saves the information contained in the ReportInfo object into the database
		/// </summary>
		/// <param name="report">ReportInfo object</param>
		/// <returns></returns>
		public bool InsertReportInfo(ReportInfo report)
		{
			string connString = WebConfigurationManager.ConnectionStrings["shoppersInfo"].ConnectionString;
			using (SqlConnection conn = new SqlConnection(connString))			
			{							
				conn.Open();				
				SqlCommand command = new SqlCommand("InsertReportInfo", conn);
				command.CommandType = CommandType.StoredProcedure;
				//Add all the parameters
				command.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Int));
				command.Parameters["@ProductID"].Value = report.ProductID;
				command.Parameters.Add(new SqlParameter("@CategoryID", SqlDbType.Int));
				command.Parameters["@CategoryID"].Value = report.CategoryID;
				command.Parameters.Add(new SqlParameter("@Browser", SqlDbType.VarChar, 256));
				command.Parameters["@Browser"].Value = report.Browser;
				command.Parameters.Add(new SqlParameter("@RequestType", SqlDbType.VarChar, 256));
				command.Parameters["@RequestType"].Value = report.RequestType;
				command.Parameters.Add(new SqlParameter("@Authenticated", SqlDbType.VarChar, 50));
				command.Parameters["@Authenticated"].Value = report.Authenticated;				
				command.ExecuteNonQuery();
				return true;									
			}
		}
	}
}

⌨️ 快捷键说明

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