473,774 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(C onfigurationSet tings.AppSettin gs["connectionStri ng"]);
SqlCommand myCommand = new SqlCommand("Por tal_UpdateConta ct",
myConnection);

// Mark the Command as a SPROC
myCommand.Comma ndType = CommandType.Sto redProcedure;

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

SqlParameter parameterUserNa me = new SqlParameter("@ UserName",
SqlDbType.NVarC har, 100);
parameterUserNa me.Value = userName;
myCommand.Param eters.Add(param eterUserName);

SqlParameter parameterName = new SqlParameter("@ Name",
SqlDbType.NVarC har, 100);
parameterName.V alue = name;
myCommand.Param eters.Add(param eterName);

SqlParameter parameterRole = new SqlParameter("@ Role",
SqlDbType.NVarC har, 100);
parameterRole.V alue = role;
myCommand.Param eters.Add(param eterRole);

SqlParameter parameterEmail = new SqlParameter("@ Email",
SqlDbType.NVarC har, 100);
parameterEmail. Value = email;
myCommand.Param eters.Add(param eterEmail);

SqlParameter parameterContac t1 = new SqlParameter("@ Contact1",
SqlDbType.NVarC har, 100);
parameterContac t1.Value = contact1;
myCommand.Param eters.Add(param eterContact1);

SqlParameter parameterContac t2 = new SqlParameter("@ Contact2",
SqlDbType.NVarC har, 100);
parameterContac t2.Value = contact2;
myCommand.Param eters.Add(param eterContact2);

myConnection.Op en();
myCommand.Execu teNonQuery();
myConnection.Cl ose();

Nov 19 '05 #1
4 1392
> 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.ed u.tw> wrote in message
news:ud******** ******@TK2MSFTN GP10.phx.gbl...
I found an example in Starter kit.
Is it so tedious to update a record.
----------------------------------------------------------------------------
-------------
SqlConnection myConnection = new
SqlConnection(C onfigurationSet tings.AppSettin gs["connectionStri ng"]);
SqlCommand myCommand = new SqlCommand("Por tal_UpdateConta ct",
myConnection);

// Mark the Command as a SPROC
myCommand.Comma ndType = CommandType.Sto redProcedure;

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

SqlParameter parameterUserNa me = new SqlParameter("@ UserName",
SqlDbType.NVarC har, 100);
parameterUserNa me.Value = userName;
myCommand.Param eters.Add(param eterUserName);

SqlParameter parameterName = new SqlParameter("@ Name",
SqlDbType.NVarC har, 100);
parameterName.V alue = name;
myCommand.Param eters.Add(param eterName);

SqlParameter parameterRole = new SqlParameter("@ Role",
SqlDbType.NVarC har, 100);
parameterRole.V alue = role;
myCommand.Param eters.Add(param eterRole);

SqlParameter parameterEmail = new SqlParameter("@ Email",
SqlDbType.NVarC har, 100);
parameterEmail. Value = email;
myCommand.Param eters.Add(param eterEmail);

SqlParameter parameterContac t1 = new SqlParameter("@ Contact1",
SqlDbType.NVarC har, 100);
parameterContac t1.Value = contact1;
myCommand.Param eters.Add(param eterContact1);

SqlParameter parameterContac t2 = new SqlParameter("@ Contact2",
SqlDbType.NVarC har, 100);
parameterContac t2.Value = contact2;
myCommand.Param eters.Add(param eterContact2);

myConnection.Op en();
myCommand.Execu teNonQuery();
myConnection.Cl ose();

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.ed u.tw> wrote:
I found an example in Starter kit.
Is it so tedious to update a record.
----------------------------------------------------------------------------
-------------
SqlConnection myConnection = new
SqlConnection( ConfigurationSe ttings.AppSetti ngs["connectionStri ng"]);
SqlCommand myCommand = new SqlCommand("Por tal_UpdateConta ct",
myConnection );

// Mark the Command as a SPROC
myCommand.Comma ndType = CommandType.Sto redProcedure;

// Add Parameters to SPROC
SqlParameter parameterItemID = new SqlParameter("@ ItemID",
SqlDbType.In t, 4);
parameterItemID .Value = itemId;
myCommand.Param eters.Add(param eterItemID);

SqlParameter parameterUserNa me = new SqlParameter("@ UserName",
SqlDbType.NVar Char, 100);
parameterUserNa me.Value = userName;
myCommand.Param eters.Add(param eterUserName);

SqlParameter parameterName = new SqlParameter("@ Name",
SqlDbType.NVar Char, 100);
parameterName.V alue = name;
myCommand.Param eters.Add(param eterName);

SqlParameter parameterRole = new SqlParameter("@ Role",
SqlDbType.NVar Char, 100);
parameterRole.V alue = role;
myCommand.Param eters.Add(param eterRole);

SqlParameter parameterEmail = new SqlParameter("@ Email",
SqlDbType.NVar Char, 100);
parameterEmail. Value = email;
myCommand.Param eters.Add(param eterEmail);

SqlParameter parameterContac t1 = new SqlParameter("@ Contact1",
SqlDbType.NVar Char, 100);
parameterContac t1.Value = contact1;
myCommand.Param eters.Add(param eterContact1);

SqlParameter parameterContac t2 = new SqlParameter("@ Contact2",
SqlDbType.NVar Char, 100);
parameterContac t2.Value = contact2;
myCommand.Param eters.Add(param eterContact2);

myConnection.Op en();
myCommand.Execu teNonQuery();
myConnection.Cl ose();


Nov 19 '05 #3
Hi,

You can rewrite this :

SqlParameter parameterItemID = new SqlParameter("@ ItemID", SqlDbType.Int,
4);
parameterItemID .Value = itemId;
myCommand.Param eters.Add(param eterItemID);

Like this :

myCommand.Param eters.Add("@Ite mID", 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.ed u.tw> wrote in message
news:ud******** ******@TK2MSFTN GP10.phx.gbl...
I found an example in Starter kit.
Is it so tedious to update a record.
-------------------------------------------------------------------------- -- -------------
SqlConnection myConnection = new
SqlConnection(C onfigurationSet tings.AppSettin gs["connectionStri ng"]);
SqlCommand myCommand = new SqlCommand("Por tal_UpdateConta ct",
myConnection);

// Mark the Command as a SPROC
myCommand.Comma ndType = CommandType.Sto redProcedure;

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

SqlParameter parameterUserNa me = new SqlParameter("@ UserName",
SqlDbType.NVarC har, 100);
parameterUserNa me.Value = userName;
myCommand.Param eters.Add(param eterUserName);

SqlParameter parameterName = new SqlParameter("@ Name",
SqlDbType.NVarC har, 100);
parameterName.V alue = name;
myCommand.Param eters.Add(param eterName);

SqlParameter parameterRole = new SqlParameter("@ Role",
SqlDbType.NVarC har, 100);
parameterRole.V alue = role;
myCommand.Param eters.Add(param eterRole);

SqlParameter parameterEmail = new SqlParameter("@ Email",
SqlDbType.NVarC har, 100);
parameterEmail. Value = email;
myCommand.Param eters.Add(param eterEmail);

SqlParameter parameterContac t1 = new SqlParameter("@ Contact1",
SqlDbType.NVarC har, 100);
parameterContac t1.Value = contact1;
myCommand.Param eters.Add(param eterContact1);

SqlParameter parameterContac t2 = new SqlParameter("@ Contact2",
SqlDbType.NVarC har, 100);
parameterContac t2.Value = contact2;
myCommand.Param eters.Add(param eterContact2);

myConnection.Op en();
myCommand.Execu teNonQuery();
myConnection.Cl ose();

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.ed u.tw> wrote in message
news:ud******** ******@TK2MSFTN GP10.phx.gbl...
I found an example in Starter kit.
Is it so tedious to update a record.
----------------------------------------------------------------------------
-------------
SqlConnection myConnection = new
SqlConnection(C onfigurationSet tings.AppSettin gs["connectionStri ng"]);
SqlCommand myCommand = new SqlCommand("Por tal_UpdateConta ct",
myConnection);

// Mark the Command as a SPROC
myCommand.Comma ndType = CommandType.Sto redProcedure;

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

SqlParameter parameterUserNa me = new SqlParameter("@ UserName",
SqlDbType.NVarC har, 100);
parameterUserNa me.Value = userName;
myCommand.Param eters.Add(param eterUserName);

SqlParameter parameterName = new SqlParameter("@ Name",
SqlDbType.NVarC har, 100);
parameterName.V alue = name;
myCommand.Param eters.Add(param eterName);

SqlParameter parameterRole = new SqlParameter("@ Role",
SqlDbType.NVarC har, 100);
parameterRole.V alue = role;
myCommand.Param eters.Add(param eterRole);

SqlParameter parameterEmail = new SqlParameter("@ Email",
SqlDbType.NVarC har, 100);
parameterEmail. Value = email;
myCommand.Param eters.Add(param eterEmail);

SqlParameter parameterContac t1 = new SqlParameter("@ Contact1",
SqlDbType.NVarC har, 100);
parameterContac t1.Value = contact1;
myCommand.Param eters.Add(param eterContact1);

SqlParameter parameterContac t2 = new SqlParameter("@ Contact2",
SqlDbType.NVarC har, 100);
parameterContac t2.Value = contact2;
myCommand.Param eters.Add(param eterContact2);

myConnection.Op en();
myCommand.Execu teNonQuery();
myConnection.Cl ose();

Nov 19 '05 #5

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

Similar topics

2
3848
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 could resolve with a simple function: Example: I have 50records - I want to update a selection of the recods - some,
3
3180
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. - The page does a read of the existing record and loads it into the gui fields for edit.
16
17019
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 must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
3
15427
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 other user was updated the record. Please tell me how can I do this. Thank you!
3
3451
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 the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
3
2415
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 table. However I put some code in to display the key field of each parent table record (parent dataset) and the value I am trying to put into the child table is there. ParentTable ChildTable ID------------------------<...
5
3543
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 do the update the changed parentid in the child table fails to change. No error is given its just that the change is not written to the Database. When I step through the records for the child table the one I would expect to be changed has a row...
5
5610
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 uses very high volume DB transactions - in the order of tens of millions per day . . . Anyway, the current database which will remain nameless, but begins with O and rymes with debacle (sorta), has a problem with high volume work when it comes to...
2
19609
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 field in table2. What I have is a form that is linked to Table2. If the users want to change a field in the main database (table1), they fill the change in to the form (which is linked to table2) If there is no change to the field, they simply...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.