bburnett
Posts: 22
|
Posted: 08/19/2008, 8:14 AM |
|
I have the following code in an After Insert event:
if(ExecuteFlag&&!ErrorFlag){
SqlCommand OrganizationInsert = new SqlCommand("OrganizationInsert", Settings.Connection1DataAccessObject);
//OrganizationInsert.CommandType = CommandType.StoredProcedure;
OrganizationInsert.Parameters.Add("@username", SqlDbType.VarChar);
OrganizationInsert.Parameters.Add("@varPassword", SqlDbType.VarChar);
SqlParameter parm = OrganizationInsert.Parameters.Add("@Organization",SqlDbType.Int);
parm.Direction = ParameterDirection.Output;
OrganizationInsert.ExecuteNonQuery;
}
I receive this error:
CS0246: The type or namespace name 'SqlParameter' could not be found
I tried adding: using System.Data.SqlClient;
but then it conflicts with ccsEmergencyActionPlan.Data;
CS0104: 'SqlCommand' is an ambiguous reference between 'System.Data.SqlClient.SqlCommand' and 'ccsEmergencyActionPlan.Data.SqlCommand'
_________________
Brandon Burnett
New Media Architect
REL Productions
West Des Moines, IA, USA
www.relonline.com |
|
|
bburnett
Posts: 22
|
Posted: 08/19/2008, 11:52 AM |
|
The best solution I found was to add using System.Data.SqlClient; to the page and be very specific for the SqlParameter and SqlCommand objects:
SqlConnection conn = new System.Data.SqlClient.SqlConnection("User ID=somebody;Initial Catalog=db;Data Source=server;password=secret");
conn.Open();
// System.Data.SqlClient.SqlCommand OrganizationInsert = new System.Data.SqlClient.SqlCommand("exec OrganizationInsert @username, @varPass, @Organization output", conn);
System.Data.SqlClient.SqlCommand OrganizationInsert = new System.Data.SqlClient.SqlCommand("OrganizationInsert", conn);
//System.Data.SqlClient.SqlCommand OrganizationInsert = new System.Data.SqlClient.SqlCommand("OrganizationInsert", Settings.Connection1DataAccessObject);
OrganizationInsert.CommandType = CommandType.StoredProcedure;
OrganizationInsert.Parameters.Add("@username", SqlDbType.VarChar, 50);
OrganizationInsert.Parameters.Add("@varPass", SqlDbType.VarChar, 50);
OrganizationInsert.Parameters["@username"].Value = item.varUsername.Value.ToString();
OrganizationInsert.Parameters["@varPass"].Value = item.varPassword.Value.ToString();
//OrganizationInsert.Parameters.Add("@Organization",SqlDbType.Int);
System.Data.SqlClient.SqlParameter parm = new System.Data.SqlClient.SqlParameter("@keyOrganization",SqlDbType.Int);
parm.Direction = ParameterDirection.Output;
OrganizationInsert.Parameters.Add(parm);
//OrganizationInsert.ExecuteReader();
OrganizationInsert.ExecuteNonQuery();
Is this the best approach?
_________________
Brandon Burnett
New Media Architect
REL Productions
West Des Moines, IA, USA
www.relonline.com |
|
|
dragoon
Posts: 173
|
Posted: 08/25/2008, 1:16 PM |
|
Yeap,
I used the same approach in one of my projects
|
|
|
bburnett
Posts: 22
|
Posted: 09/02/2008, 1:06 PM |
|
Thanks Dragoon.
Anyone know the best way to get the database connection string specified in web.config?
So that I don't have to hard code it?
_________________
Brandon Burnett
New Media Architect
REL Productions
West Des Moines, IA, USA
www.relonline.com |
|
|
|