Data type conversion issue

This is a discussion on Data type conversion issue within the C Programming forums, part of the General Programming Boards category; Hi I am using odbc with MS Sql server database. One of my Stored proc returns "varchar" data in one ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    5

    Data type conversion issue

    Hi

    I am using odbc with MS Sql server database.


    One of my Stored proc returns "varchar" data in one column (say Column1).

    In C code I am trying to convert this data to char type.

    If the Column1 = "foo2"

    I am able to get value "foo" in C variable.

    I want to fetch correct value "foo2" in my C variable.

    Do i need to apply any conversion here ?

    Please help.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Without showing the relevant part of your code nobody here is propably able to help you.

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    5
    I can not paste original code, as it is against org policy. I can try to explain with e.g
    As per odbc steps to connect sql server we are doing following things
    I am passing void pointer from C code for binding output from stored proc.
    Code:
    void *data
    step1: Connection creation, Command preparation and execution
    step 2: Using SQLDescribeCol function i try to find column attributes. such as data type, lenght etc..
    e.g

    Code:
    if(datatype == SQL_VARCHAR)
    {
    ctype=SQL_C_CHAR;
    }
    step 3: Using SQLBindCol(cmd, 1, ctype, data, sizeof(data), &indicator)
    step 4:
    Code:
    while(SQLFETCH(cmd))
    { parseData(data);}
    void parseData(void *data, type)
    { if(type =SQL_VARCHAR) 
    { 
    char val[] ;
    val = (char *)data;
    } 
    }
    Note: Their might be syntax error in this code. This is just for reference

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    > I can not paste original code, as it is against org policy.
    Then I'm guessing it's against org policy to ask questions on a public forum about a slightly modified version?

    You're not following org rules any better, actually, all you're doing is making it highly unlikely that you'll receive any help. We'd be wasting time trying to help you fix a bunch of crappy pseudocode, instead of the problem you're trying to solve.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-14-2011, 10:26 PM
  2. Float data type issue
    By Figen in forum C Programming
    Replies: 2
    Last Post: 01-31-2011, 01:42 PM
  3. Mayan Calander Conversion Issue
    By AKalair in forum C Programming
    Replies: 1
    Last Post: 11-30-2007, 11:26 AM
  4. difference between type conversion and type casting
    By Bargi in forum C Programming
    Replies: 1
    Last Post: 01-23-2007, 03:17 AM
  5. conversion for binary data type
    By DMaxJ in forum C++ Programming
    Replies: 2
    Last Post: 10-23-2001, 01:57 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21