is it so tedious to update a record

A

ad

I found an example in Starter kit.
Is it so tedious to update a record.


----------------------------------------------------------------------------
-------------
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("Portal_UpdateContact",
myConnection);

// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;

// Add Parameters to SPROC
SqlParameter parameterItemID = new SqlParameter("@ItemID",
SqlDbType.Int, 4);
parameterItemID.Value = itemId;
myCommand.Parameters.Add(parameterItemID);

SqlParameter parameterUserName = new SqlParameter("@UserName",
SqlDbType.NVarChar, 100);
parameterUserName.Value = userName;
myCommand.Parameters.Add(parameterUserName);

SqlParameter parameterName = new SqlParameter("@Name",
SqlDbType.NVarChar, 100);
parameterName.Value = name;
myCommand.Parameters.Add(parameterName);

SqlParameter parameterRole = new SqlParameter("@Role",
SqlDbType.NVarChar, 100);
parameterRole.Value = role;
myCommand.Parameters.Add(parameterRole);

SqlParameter parameterEmail = new SqlParameter("@Email",
SqlDbType.NVarChar, 100);
parameterEmail.Value = email;
myCommand.Parameters.Add(parameterEmail);

SqlParameter parameterContact1 = new SqlParameter("@Contact1",
SqlDbType.NVarChar, 100);
parameterContact1.Value = contact1;
myCommand.Parameters.Add(parameterContact1);

SqlParameter parameterContact2 = new SqlParameter("@Contact2",
SqlDbType.NVarChar, 100);
parameterContact2.Value = contact2;
myCommand.Parameters.Add(parameterContact2);

myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
 
K

Kevin Spencer

Is it so tedious to update a record.

Compared to what?

There are all kinds of database apps. There are all kinds of database
operations. There are all kinds of ways of getting it done. Your example
shows one approach to doing a database update in a specific set of
circumstances. It is not an example of the only way to update a database
under any circumstances.

An example is just that: an example. It is usually for the purpose of
demonstrating one or a few aspects of a programming technology. It is not
meant as a template for everything you do with databases.

As for tedious, well, that's subjective. I occasionally run into some jobs
that I consider tedious. However, I couldn't tell you whether those jobs
would be considered tedious by everyone. In my case, tedious is something
I've done many times before. However, in your case, tedious is apparently
something entirely different.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
K

Ken Dopierala Jr.

Hi,

You can rewrite this :

SqlParameter parameterItemID = new SqlParameter("@ItemID", SqlDbType.Int,
4);
parameterItemID.Value = itemId;
myCommand.Parameters.Add(parameterItemID);

Like this :

myCommand.Parameters.Add("@ItemID", SqlDbType.Int).Value = itemId;

This will cut the number of lines of code you are typing to 1/3. Other than
that you'll need to use a 3rd party tool that autogenerates SP calls. I've
never used one so I don't have one to recommend. Good luck! Ken.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top