SQLDATA ADAPTER WILL NOT UPDATE

S

Steve Wolfie

I posted a few days ago and got some guidance about how to go about fixing
my problem...

I rewrote a ton of code and still have the same problem... SOMEONE PLEASE
HELP!!!

The problem I think has to do with postback, but not sure how to control it.

Follows the code for the update feature:
Public Function updaterecord(ByVal id As Integer, ByVal MoldexRep As String,
ByVal airgasregion As String, ByVal branchno As String, ByVal city As
String, ByVal keycontact As String, ByVal phone As String, ByVal BranchType
As String, ByVal Inicontactdate As String, ByVal participate As String,
ByVal meetingdate As String, ByVal stockingbranch As String, ByVal POPLaced
As String, ByVal NoISReps As String, ByVal NoOSReps As String, ByVal
comments As String)

InitializeComponentforupdate()

sqlupdate.Parameters("@ID").Value = id

sqlupdate.Parameters("@MoldexRep").Value = MoldexRep

sqlupdate.Parameters("@AirgasRegion").Value = airgasregion

sqlupdate.Parameters("@BranchNo").Value = branchno

sqlupdate.Parameters("@City").Value = city

sqlupdate.Parameters("@Keycontact").Value = keycontact

sqlupdate.Parameters("@Phone").Value = phone

sqlupdate.Parameters("@BranchType").Value = BranchType

sqlupdate.Parameters("@IniContactDate").Value = Inicontactdate

sqlupdate.Parameters("@Participate").Value = participate

sqlupdate.Parameters("@MeetingDate").Value = meetingdate

sqlupdate.Parameters("@StockingBranch").Value = stockingbranch

sqlupdate.Parameters("@POPLaced").Value = POPLaced

sqlupdate.Parameters("@NoISReps").Value = NoISReps

sqlupdate.Parameters("@NoOSReps").Value = NoOSReps

sqlupdate.Parameters("@Comments").Value = comments

sqlcn.Open()

sqlda.UpdateCommand.ExecuteNonQuery()

sqlcn.Close()

End Function
 
S

Steve Wolfie

Okay, now it seems only to be certain fields...
When I am using the dropdown box for a field, it does not update.
 
S

Steven Cheng[MSFT]

Hi Steve,

Welcome to ADONET newsgroup.
From your description and the code snippet you provided, you're wanting to
executing a certain UPDATE SQL statement in ASP.NET page's code and met
some problems, yes?

Based on my understanding, we can directly use SqlCommand object (and a
SqlConnection object) to execute sqlstatement without SqlDataAdapter. Is
there any particular requirement that you need to use DAtaAdapter such as
updateing DataSet/DataTable?

Also, what's the detailed problem you encountered when executing the update
functiob? Is there any error message or other error info?

If there're any thing else I misunderstand, please feel free to let me
know. Looking forward to your response.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steve Wolfie

Thanks for responding...

Thanks for welcoming me to the ADO Newsgroup.

I fixed the problem, I wasn't specifying all the parameters in the
updatecommand.commandtext property.

However, I am intrigued at the idea of cutting out the da altogether. How
can this be done?

Also, where can i find info on optimizing my code? I was watching system
resource usage using task manager and process explorer (from sysinternals)
and see that this relatively small operation is causing lots of memory and
processor time allocations. I am just kinda left feeling like the way I am
writing code is not taking advantage of performance optimizations....

I also wrote a class to do this work for me, and have the asp page simply
supply the arguments for the function... is this smart?

thanks for all the help...
 
S

Steven Cheng[MSFT]

Thanks for your response Steve,

As for the " cutting out the da altogether.", I just meant that we can use
SqlCommand directly with a SqlConnection(without DataAdapter). For example:
==================
string mySelectQuery = "SELECT OrderID, Customer FROM Orders WHERE OrderID
= @OrderID";

SqlConnection myConnection = new SqlConnection(myConnString);

SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);

//add the parameters.....

myConnection.Open();

SqlDataReader myReader = myCommand.ExecuteReader();

try
{
while (myReader.Read())
{
Console.WriteLine(myReader.GetInt32(0) + ", " +
myReader.GetString(1));
}
}
finally
{
// always call Close when done reading.
myReader.Close();
// always call Close when done reading.
myConnection.Close();
}
==================

This is a typical code snippet for using SqlCommand. The reason we use
DataAdapter is because it provide the functions to update and query data
with a DataSet, that provide the batch update ability. So which approach
to use (DataAdapter or SqlCommand) depend on the actual scenario and
requirement.

For reference on how to improve the performance of our dataaccessing code,
here are some MSDN reference and tech articles:

#Chapter 12 - Improving ADO.NET Performance
http://msdn.microsoft.com/library/en-us/dnpag/html/scalenetchapt12.asp?frame
=true

#Checklist: ADO.NET Performance
http://msdn.microsoft.com/library/en-us/dnpag/html/scalenetcheck01.asp?frame
=true

#Inside ADO.NET Batch Update
http://msdn.microsoft.com/library/en-us/dndive/html/data11082001.asp?frame=t
rue


In addition, as for the
===========
I also wrote a class to do this work for me, and have the asp page simply
supply the arguments for the function... is this smart?
============

Of course, I think it's good to encapsulate Data Accessing code into
certain Functions or a certain Utility class. In fact, in most
applications, we will define some classes which focus on dataaccessing ,
then we use these classes in our Front UI's code( for web application, we
just use the DataAccessing classes in asp.net page code), this can separate
our DataAccessing code logic from our Front UI processing code logic.

If you have interests, I suggest you also have a look at the DataAccess
Application Block within the Enterprise Library which will be helpful for
encapsulating DataAccess code in our NTier application:

#Data Access Application Block
http://msdn.microsoft.com/library/en-us/dnpag2/html/daab.asp?frame=true

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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