Click here to Skip to main content
13,049,814 members (74,866 online)
Rate this:
Please Sign up or sign in to vote.
See more: , +
Hi experts,

I am Using Microsoft Visual Studio 2005 and MSSQL Server 2005.

In my Website i am using ODBC Connection using "System DSN".
In my code of get Data, it is working successfully.

But, in my code of Insert Data to Database,
I am Execution Non Query which is not taking effect in database.

My Function is as under.

public int Savedata(OdbcParameter[] p)
        int i = 0;
        con = new OdbcConnection(ConfigurationManager.ConnectionStrings["connStr"].ToString());
        cmd = new OdbcCommand();
        cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Save_Employee";
            i = cmd.ExecuteNonQuery();
            return i;
        catch (Exception ex)
            throw ex;

My Connection string is :
<add name="connStr" connectionString="DSN=TestODBC;Uid=myUserName;Pwd=MyPassword;"/>

Please note that -
1. my all code is working fine with SqlConnection insted of OdbcConnection.
2. Stored Procedure "Save_Employee" is working fine with SqlConnection insted of OdbcConnection.
3. but when i convert all code to OdbcConnection, the ExecuteNonQuery is success but no any record inserted in database.

Any one can help me...?
Thanks in advance your any kind of help.
Posted 4-Jan-13 0:13am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You must use the full ODBC call syntax. It also doesn't use named parameters, so you would use a question mark in each param's place
cmd.CommandText = "exec Save_Employee ?, ?, ?";

if you had 3 parameters.

For further reading:[^]
Mr. Mahesh Patel 4-Jan-13 23:26pm
Thanks a lot, I got Solution.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

How are you passing the parameters that needs to be updated to the stored procedure. I think you are missing a lot of SqlParameters and you also don't need to call the cmd.Parameters.Clear();

If your stored procedure is not expecting any parameter from the outside world then perhaps we need to look into the procedure to figure out the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100