Issues with AddInParameter() -- VS 2008 / .NET 3.5

Topics: Data Access Application Block, Enterprise Library Core
May 10, 2010 at 10:18 PM

Hello all,

I tried to dig around in the documentation pretty thoroughly but I'm new to EntLib and might be missing something. Hoping that I can at least pave the way for other newcomers.

I'm trying to do a simple INSERT statement into one SQL2005 database table.

Process should work as follows: button clicked on ASP.NET page --> Fires event --> new instance of a TeaserResponse() class with form data supplied --> Adds the form data to the database.

Code from the Event in the CodeBehind File:

    public void SignUpbutton_Click(object sender, ImageClickEventArgs e)
        string newName = TextBoxName.Text;
        string newEMail = TextBoxEmail.Text;
        bool isAdmin = CheckBoxAdmin.Checked;
        bool isStudent = CheckBoxStudent.Checked;
        bool isTeacher = CheckBoxTeacher.Checked;
        bool isOther = CheckBoxOther.Checked;

        TeaserResponse response = new TeaserResponse(newName, newEMail, isTeacher, isAdmin, isStudent, isOther);


Code from the TeaserResponse class (all code so you can see references, etc.):

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.Common;

namespace StudentVault.TeaserUI.Repository
public class TeaserResponse

// Member Variables private string _name;
private string _email;
private bool _isTeacher;
private bool _isStudent;
private bool _isAdmin;
private bool _isOther;
private Database _db;

// Public Properties public string Name
get { return _name;

set { _name = value; } } public string EMail
get { return _email;

set { _email = value; } } public bool IsAdmin
get { return _isAdmin;

set { _isAdmin = value; } } public bool IsStudent
get { return _isStudent;

set { _isStudent = value; } } public bool IsTeacher
get { return _isTeacher;

set { _isTeacher = value; } } public bool IsOther
get { return _isOther;

set { _isOther = value; } } public Database DB
get { return _db;

set { _db = value; } } // Constructors public TeaserResponse(string newName, string newEmail, bool newIsTeacher, bool newIsAdmin, bool newIsStudent, bool newIsOther)
this.Name = newName;
this.EMail = newEmail;
this.IsAdmin = newIsAdmin;
this.IsOther = newIsOther;
this.IsStudent = newIsStudent;
this.IsTeacher = newIsTeacher;

//tring connStr = ConfigurationManager.ConnectionStrings["SVProd"]; //this.DB = new SqlDatabase(connStr); this.DB = EnterpriseLibraryContainer.Current.GetInstance<Database>();


//Methods public void AddResponse()
using (DbConnection conn = this.DB.CreateConnection())
DbTransaction trans = conn.BeginTransaction();

try { string SQLcmd = "INSERT INTO sv_TeaserResponses (Name, EMail, teacher, student, admin, other) VALUES (@Name, @EMail, @teacher, @student, @admin, @other)";
DbCommand cmd = DB.GetSqlStringCommand(SQLcmd);
                    DB.AddInParameter(cmd, "@Name", DbType.String, this.Name);
                    DB.AddInParameter(cmd, "@EMail", DbType.String, this.EMail);
                    DB.AddInParameter(cmd, "@admin", DbType.Boolean, this.IsAdmin);
                    DB.AddInParamater(cmd, "@teacher", DbType.Boolean, this.IsTeacher);
                    DB.AddInParamater(cmd, "@student", DbType.Boolean, this.IsStudent);
                    DB.AddInParamater(cmd, "@other", DbType.Boolean, this.IsOther); DB.ExecuteNonQuery(cmd, trans); trans.Commit(); } catch { trans.Rollback(); throw new Exception("Whoa!");



When I attempt to compile the code, I get the following error on the line "DB.AddInParamater(cmd, "@teacher", DbType.Boolean, this.IsTeacher);" and each similar statement after that (3 of these errors in all):

'Microsoft.Practices.EnterpriseLibrary.Data.Database' does not contain a definition for 'AddInParamater' and no extension method 'AddInParamater' accepting a first argument of type 'Microsoft.Practices.EnterpriseLibrary.Data.Database' could be found (are you missing a using directive or an assembly reference?)


What's confusing me is that it doesn't mark the preceding three lines as having anything wrong with them and only marks the second DbType.Boolean statement as an error, so it's not the data type difference either, I don't think.


If anyone could help me dig into this, I'd really appreciate it as a newcomer to the EntLib community.


May 11, 2010 at 3:48 AM

Hi SeanKilleen,  

AddInParameter are misspelled in the following lines,  

                    DB.AddInParameter(cmd, "@admin", DbType.Boolean, this.IsAdmin);           => Correct
                    DB.AddInParamater(cmd, "@teacher", DbType.Boolean, this.IsTeacher);     => Misspelled
                    DB.AddInParamater(cmd, "@student", DbType.Boolean, this.IsStudent);     => Misspelled
                    DB.AddInParamater(cmd, "@other", DbType.Boolean, this.IsOther);           => Misspelled

It should work fine once this is properly set.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.


May 11, 2010 at 1:29 PM

...Wow. Beginner's mistake, indeed. Too much time in front of the keyboard. :)


Thank you @AvandeSupport! Really appreciate the quick response.