CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> .NET

 Output Parameters with C#

Print topic Send  topic

Author Message
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
View profile  Send private message
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
View profile  Send private message
dragoon


Posts: 173
Posted: 08/25/2008, 1:16 PM

Yeap,

I used the same approach in one of my projects
View profile  Send private message
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
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.