473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

is it so tedious to update a record

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();

Nov 19 '05 #1
4 1376
> 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.

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
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();

Nov 19 '05 #2
As Kevin says - there are many ways to accomplish the same task. If
you think the code is tedious to write, let some tools autogenerate
the code for you:

http://blog.hundhausen.com/PermaLink...5-a582fde8a0fc

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 29 Mar 2005 20:34:10 +0800, "ad" <ad@wfes.tcc.edu.tw> wrote:
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();


Nov 19 '05 #3
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.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
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();

Nov 19 '05 #4
Data Access code such as this can be dramatically simplified by using
Microsoft's free Data Application Block.
Here's more info:
http://aspnet.4guysfromrolla.com/articles/070203-1.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
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();

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
3
by: Fred | last post by:
Hi out there, I have problems finding a way to warn a user that another user intends soon to update the same specific row. Let me explain. User 1 get to a JSP "update customer record" page....
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: Mihaly | last post by:
I want to update a record into a table in SQL Server 2000 database from C#. This table is used concurently for other users too, and I want to be sure that from the read of record to the update no...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
3
by: PAUL | last post by:
Hello, I have 2 datasets I am trying to update. The parent table seems to update fine but when I go update the chiled table I get an error message that says I need a related record in the parent...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
5
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.