473,725 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

odbc adapter syntax HELP make it do the update

this is the call

private void Page_Load(objec t sender, System.EventArg s e)
{
OdbcConnection connection = new OdbcConnection ("DSN=PFW52" );
CreateDataAdapt er(connection);
}

this is the code, no errors, but NO UPDATE I have to use ODBC I just
need to update a field based on a key, EMBARASSED to say days going
around syntax PLEASE SOMEONE

public static OdbcDataAdapter CreateDataAdapt er(OdbcConnecti on
connection)
{
string selectCommand ="SELECT rtrim(Commodity Key),
CommodityShortD escr FROM INCOMMOD";

OdbcDataAdapter adapter = new OdbcDataAdapter (selectCommand,
connection);

adapter.UpdateC ommand = new OdbcCommand( "UPDATE INCOMMOD SET
CommodityShortD escr = ? WHERE rtrim(Commodity Key) = ?");

adapter.UpdateC ommand.Paramete rs.Add("@Commod ityKey",
OdbcType.Char, 8, "CommodityKey") ;

adapter.UpdateC ommand.Paramete rs.Add("@Commod ityShortDescr",
OdbcType.Char, 1, "CommodityShort Descr");

adapter.UpdateC ommand.Paramete rs["@CommodityShor tDescr"].Value = "X";

return adapter;

}

no errors, no update occurs, the statement runs on server engine using
pervasive SQL and control center the update statement works.

Mar 11 '06 #1
1 2532
Cindy:

Two things. First, ODBC doesn't support named parameters if I remember
correctly so even if you name them, they appear in the same respect that
they were entered. As long as you add them to the collection so that the
First parameter you need in the Sql Statement corresponds to the first
parameter in the collection, you'll be fine. This isn't your problem though,
I mention it only for informational purposes.

Where are you filling your DataTable though? I'm guessing it's filled
somewhere else. So first you need to make sure it's filled.

The problem appears to be that you don't call Update on the adapter
anywhere. Somewhere you'll need to call
adapter.Update( DataSetOrDataTa bleYou Filled).

Assuming that you are calling Update, the problem very well may be that you
don't have changes in the DataTable.
When an adapter's Update method is called, it loops through every row and
checks the RowState value of each row. If the row is Updated, then it uses
the Update command provided one is specified. If not, an exception is
thrown. If the rowstate is Deleted, then it will use the Deletecommand.
Same for Inserted.

So right before the Update call, you need to verify that you have changes.
If you don't, then nothing will get sent to the DB. You can use
Debug.Assert(Da taSetOrDataTabl eName.HasChange s, "No Changes are present so
nothing will be updated");

Check the assertion, if it doesn't fail, then the problem is either with the
Update logic, the parameter/column mapping or something else. Most of the
stuff that would be 'something else' would throw an exception though .

Also, be very careful about the state of the datatable. On Page_Load, you
probably want to use

private DataTable CurrentData = null;
private OdbcDataAdapter MyAdapter = null;
if(!Page.IsPost Back){
OdbcConnection connection = new OdbcConnection( "DSN=PFW52" );
MyAdapter = CreateDataAdapt er(connection);
Session["MyAdapter"] = MyAdapter;//In each case you could use ViewState
instead of Session (same goes for CurrentTable - I just used Session for
simplicity
try{
MyAdapter.Fill( CurrentData);
Session["CurrentDat a"] = CurrentData;
}
catch(OdbcExcep tion ex){
//Log and respond to exception
}
}
else{
if(Session["CurrentDat a"] != null){
CurrentData = Session["CurrentDat a"] as DataTable;
}
}
In each block, after you have CurrentData populated you can use it as you
normally would.

To update, you'd have a button or somethign else that calls something like
this...

private Boolean UpdateDataTable (){
try{
if(Session["MyAdapter"] == null){
MyAdapter = CreateDataAdapt er(connection);
}
MyAdapter.Updat e(MyDataTable);
Session["MyDataTabl e"] = MyAdapter;
}
catch(OdbcExcep tion ex){
//Log and respond to exception according to your application's rules
}
}

Remember that each case where I use Session, it could just as easily be
viewstate. And the exact logic of what you store and where will depend on
your application. This is by no means the only way to handle State of your
objects, I just used this method for clarity. The main point is making sure
you have changes in your dataTable and calling Update. (also, i used a
datatable here for clarity, DataTables don't have a HasChanges method, so if
you want to check Rowstate that way, you'll need to create a DataSet and add
CustomTable to it. Again, I did it the way I did just for brevity.

If you don't understand anything, if I didn't understand the problem and
answered a different question from the one you asked, or if this doesn't fix
your problem, please let me know and I'll do my best to help.

Cheers,
Bill

"cindy" <CM****@tams.co m> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
this is the call

private void Page_Load(objec t sender, System.EventArg s e)
{
OdbcConnection connection = new OdbcConnection ("DSN=PFW52" );
CreateDataAdapt er(connection);
}

this is the code, no errors, but NO UPDATE I have to use ODBC I just
need to update a field based on a key, EMBARASSED to say days going
around syntax PLEASE SOMEONE

public static OdbcDataAdapter CreateDataAdapt er(OdbcConnecti on
connection)
{
string selectCommand ="SELECT rtrim(Commodity Key),
CommodityShortD escr FROM INCOMMOD";

OdbcDataAdapter adapter = new OdbcDataAdapter (selectCommand,
connection);

adapter.UpdateC ommand = new OdbcCommand( "UPDATE INCOMMOD SET
CommodityShortD escr = ? WHERE rtrim(Commodity Key) = ?");

adapter.UpdateC ommand.Paramete rs.Add("@Commod ityKey",
OdbcType.Char, 8, "CommodityKey") ;

adapter.UpdateC ommand.Paramete rs.Add("@Commod ityShortDescr",
OdbcType.Char, 1, "CommodityShort Descr");

adapter.UpdateC ommand.Paramete rs["@CommodityShor tDescr"].Value = "X";

return adapter;

}

no errors, no update occurs, the statement runs on server engine using
pervasive SQL and control center the update statement works.

Mar 11 '06 #2

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

Similar topics

1
2887
by: simianphile | last post by:
OK, I had a problem that I've now fixed but I can't really understand what was causing it in the first place. I have an intranet site that uses basic authentication to allow users to view and update information from an Oracle DB (ver 8.1.6 -- ancient, I know). Anyway, the site worked fine as long as the machine accessing the ASP page was running Win 2k but when an XP machine tried to view the page, the client got an error: Microsoft...
0
6648
by: Steve Barker | last post by:
I am trying to access Paradox through a .NET Windows application I am writing. I have added a Data Connection to the Paradox table in the Server Explorer of Visual Studio .NET. I have used the "Microsoft OLD DB Provider for ODBC Drivers" option to make the connection. This works fine... even though the Paradox table is password protected. I have dragged a the table from the Server Explorer to my form to make a connection object and a data...
14
10141
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought I should give back to the community by posting our findings. Thanks you all for all your help till now by posting problems and their solutions. ~Abhijit
0
1768
by: compuglobalhypermeganetz0r | last post by:
I am having trouble getting an adapter to update my access database, it gives the error Syntax error in INSERT INTO statement. for Line 98: Adapter.Update(WineDS, "tblWines") Below is my code: <%@ Control Explicit="True" Language="VB" Debug="True" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %>
1
1060
by: news.microsoft.com | last post by:
I have used typed datasets by creating a Data Component (data.vb) by creating a new component in a vb or asp/vb.net project, dragging data tables onto the component, which generates the connection and adapters for me. After getting everything set up the way I like it, I then tell it to generate a dataset (let's call that ds.xsd) and place that on the component as well. Then all I need to do is add the fill method, update method, etc for...
17
3827
by: Benoit Martin | last post by:
I'm working on a project in VB.net connecting to a SQL Server 2000 database that I can't modify I created a dataset with a schema identical to the DB. When trying to update the DB from the dataset using the dataAdapter.update sub, I get an error. The problem seems to be that one of the fields was named 'desc' which is a reserved word for SQL. I've been able to work around this design flaw 'till now but it looks like the update sub can't...
0
2705
by: NM | last post by:
Hello, I've got a problem inserting binary objects into the postgres database. I have binary objects (e.g. images or smth else) of any size which I want to insert into the database. Funny is it works for files larger than 8000 Bytes. If a file is less than 1000 Bytes I get the following message: Error message: --invalid input syntax for type oid: "\074\077......";
0
1255
by: =?Utf-8?B?QnJpYW4gSi4gTWF0dXNjaGFr?= | last post by:
Greetings: I am attempting to use one dropdownlist to filter the contents of another as demonstrated within this MSDN article: http://msdn2.microsoft.com/en-us/library/aa581791.aspx. Oracle 10 is the backend in this case, and it is my understanding that the OLE DB provider in Oracle for Visual Studio 2005 supports V8. So, I'm using the OLE DB provider for ODBC. However, I'm using ASP .NET as the interface, and my table adapter...
6
2944
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1) Constraint pk_table1 Primary Key,
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
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
6011
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
4517
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
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2157
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.