Database Stored Procedures in .NET - TechRepublic
General discussion
November 14, 2005 at 05:00 PM
m_a_r_k

Database Stored Procedures in .NET

by m_a_r_k . Updated 18 years, 6 months ago

I am having a problem using .NET to implement a stored procedure for inserting a row into a database. FYI, I am using C# and SQL Server. None of the code examples in MSDN show the specific table that is being accessed. What parameter of what object do I set to provide the table name. The code shown below is directly from MSDN. It somehow inserts into the table ‘Category’. But where in the world is this table name given in the code? This example is from MSDN 2003, .NET Framework->Programming wiht .NET Framework->Using .NET Framework Data Providers…->Performing Database Operations…->Modifying Data in a Database. Thanks in advance.

[pre]
SqlCommand insertCatCMD = new SqlCommand(“InsertCategory” , nwindConn);
insertCatCMD.CommandType = CommandType.StoredProcedure;

SqlParameter workParm;

workParm = insertCatCMD.Parameters.Add(“@RowCount”, SqlDbType.Int);
workParm.Direction = ParameterDirection.ReturnValue;

workParm = insertCatCMD.Parameters.Add(“@CategoryName”, SqlDbType.NChar, 15);

workParm = insertCatCMD.Parameters.Add(“@Identity”, SqlDbType.Int);
workParm.Direction = ParameterDirection.Output;

insertCatCMD.Parameters[“@CategoryName”].Value = “New Category”;
insertCatCMD.ExecuteNonQuery();
[/pre]

This discussion is locked

All Comments