[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Sybase SQL Anywhere + ODBC.NET

Alexander Glazkov

3/6/2002 6:56:00 PM

Hi,


I'm using Sybase SQL Anywhere 6 and connecting thru
ODBC.NET. When I'm
trying to update a record, ExecuteNonQuery() returns 1,
but no records
updated. I do use BeginTransaction() and Commit().
What could be the problem?

Thanks in advance,
Alex


4 Answers

(David Sceppa)

3/6/2002 9:48:00 PM

0

GL

3/7/2002 12:36:00 AM

0

David,

Thank you for your reply.
The table I want to update has a autoincrement field which is not in the
primary key. The primary key consists of 2-3 other fields.

Alex

"David Sceppa" <davidsc@online.microsoft.com> wrote in message
news:EWfvqAVxBHA.2120@cpmsftngxa07...
> Alex,
>
> Does that happen with all UPDATE queries? I've seen this
> behavior before if you have a trigger on the table you're trying
> to update and that trigger modifies one row.
>
> David Sceppa
> Microsoft
> This posting is provided "AS IS" with no warranties,
> and confers no rights. You assume all risk for your use.
> © 2002 Microsoft Corporation. All rights reserved.


GL

3/7/2002 9:55:00 AM

0

David,

some more food for thoughts:

1) This is the initial code:

odbcConnection = new System.Data.Odbc.OdbcConnection();
odbcConnection.ConnectionString =
"DSN=myDSN;UID=dba;PWD=sql;DatabaseFile=C:\\\\TheProject\\\\TheDatabase.db;"
+ "AutoStop=YES;Integrated=NO;Debug=NO;DisableMultiRowFetch=NO";
odbcConnection.Open();
OdbcTransaction trans;
trans = odbcConnection.BeginTransaction();

try {

// Use params here
String updSql = "UPDATE A_TAB set a_char_field_id = ? where
an_autoincremen_field = ?";
OdbcCommand updCmd = new OdbcCommand(updSql, odbcConnection);
updCmd.Transaction = trans;
updCmd.Parameters.Add("@char_fld", OdbcType.VarChar, 30).Value =
MyId.Text;
updCmd.Parameters.Add("@auto_inc", OdbcType.Int).Value = id;
updCmd.ExecuteNonQuery();
trans.Commit();
} catch(Exception e1) {
trans.Rollback();
Response.Write(e1.ToString());
} finally {
odbcConnection.Close();
}
}

MyId is described as <asp:TextBox id="MyId" width="100%" runat="server"/>

This code does not work.

2) Now, lets replace the line:
updCmd.Parameters.Add("@char_fld", OdbcType.VarChar, 30).Value =
MyId.Text;
with
String s = MyId.Text;
updCmd.Parameters.Add("@char_fld", OdbcType.VarChar, 30).Value =
s;

Does not work either

3) Lets replace the line:
updCmd.Parameters.Add("@char_fld", OdbcType.VarChar, 30).Value =
MyId.Text;
with
String s = "MyStaticString";
updCmd.Parameters.Add("@char_fld", OdbcType.VarChar, 30).Value =
s;

This code works.
Did I miss something?

Thanks,
Alexander Glazkov (GL)



Soren Forsdahl

3/27/2002 10:37:00 AM

0

Hey.
I just started to learn about odbc with vb .net.
I use also Sybase SQL Anywhere 6 i my work.
But we use clarion to code in, but we shall move to
vb .net.
But we have to use Sybase SQL Anywhere 6 databas.
Have you any sample that i can get to se who it wold be??

Greetz Soren Forsdahl
Analys Consult KB
Sweden


>-----Original Message-----
>David,
>
>some more food for thoughts:
>
>1) This is the initial code:
>
>odbcConnection = new System.Data.Odbc.OdbcConnection();
> odbcConnection.ConnectionString >"DSN=myDSN;UIDÛa;PWD=sql;DatabaseFile=C:\\\\TheProject\\
\\TheDatabase.db;"
>+ "AutoStop=YES;Integrated=NO;Debug=NO;DisableMultiRowFetc
h=NO";
> odbcConnection.Open();
>OdbcTransaction trans;
>trans = odbcConnection.BeginTransaction();
>
>try {
>
> // Use params here
> String updSql = "UPDATE A_TAB set
a_char_field_id = ? where
>an_autoincremen_field = ?";
> OdbcCommand updCmd = new OdbcCommand(updSql,
odbcConnection);
> updCmd.Transaction = trans;
> updCmd.Parameters.Add("@char_fld",
OdbcType.VarChar, 30).Value >MyId.Text;
> updCmd.Parameters.Add("@auto_inc",
OdbcType.Int).Value = id;
> updCmd.ExecuteNonQuery();
> trans.Commit();
> } catch(Exception e1) {
> trans.Rollback();
> Response.Write(e1.ToString());
> } finally {
> odbcConnection.Close();
> }
> }
>
>MyId is described as <asp:TextBox id="MyId" width="100%"
runat="server"/>
>
>This code does not work.
>
>2) Now, lets replace the line:
> updCmd.Parameters.Add("@char_fld",
OdbcType.VarChar, 30).Value >MyId.Text;
>with
> String s = MyId.Text;
> updCmd.Parameters.Add("@char_fld",
OdbcType.VarChar, 30).Value >s;
>
>Does not work either
>
>3) Lets replace the line:
> updCmd.Parameters.Add("@char_fld",
OdbcType.VarChar, 30).Value >MyId.Text;
>with
> String s = "MyStaticString";
> updCmd.Parameters.Add("@char_fld",
OdbcType.VarChar, 30).Value >s;
>
>This code works.
>Did I miss something?
>
>Thanks,
>Alexander Glazkov (GL)
>
>
>
>.
>