Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# Update method from Form to DataClass
Message
 
To
09/11/2004 19:41:27
General information
Forum:
ASP.NET
Category:
Web forms
Environment versions
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
00959753
Message ID:
00960481
Views:
11
Bonnie;


Thank you for your suggestion! It got me to think and resolving this was not an easy issue. I would try changing just one word or concept and have many errors. Then I would have my Form free or errors only to find that there was a problem calling the Data Class. This issue went back and forth.

I did learn a great deal from this exercise about how to use C# and why a specific approach is taken. I would compare my experience resolving this issue with walking through a Mine Field! One step in the wrong place and then the “fun begins”!

Another analogy is a large room filled with mousetraps each having a Ping Pong Ball delicately placed upon it. The object of the exercise is to bounce one Ping Pong Ball across the room without setting off another. If one is set off then WOW! There goes the room! :)

Here is the basic concept that works.


On the Form:
static string UserID;
static string FirstName;


if (Condition == "Save")
{
     UserID = txtUserID.Text;
     FirstName = txtFirstName.Text;
     UpdateOneUser(UserID, FirstName);

private void UpdateOneUser(string UserID, string FirstName)
{
	ScrapDB.UpdateUser(UserID, FirstName);
}
In the Data Class:
public static void UpdateUser(string UserID, string FirstName)  // 
{
     SqlConnection UpdateUserConnection = GetConnection();
     string UpdateStatement	= "UPDATE UserInfo SET FirstName = @FirstName WHERE UserID=@UserID";
		
			
     SqlCommand UpdateCommand = new SqlCommand(UpdateStatement, UpdateUserConnection);
		UpdateCommand.Parameters.Add("@UserID", UserID);
		UpdateCommand.Parameters.Add("@FirstName", FirstName);
					
		UpdateUserConnection.Open();

		UpdateCommand.ExecuteNonQuery();
	
		UpdateUserConnection.Close();
}
What was of key importance in resolving two major issues was the use and understanding of the word static. This occurred on both the Form and Data Class. This was an excellent experience.

Tom
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform