Skip to main content
Known Participant
May 4, 2009
Question

How to get string value from database table using Visual Studio 2005?

  • May 4, 2009
  • 1 reply
  • 991 views

Hi,

Im developing plugin in illustrator cs3 using visual studio 2005. I need to get the values eneterd in database. Im able to get the integer values. But while getting string values it is returning empty value.

Im using the below code to get the values from database table

bool Table::Get(char* FieldName,int& FieldValue)
{
    try
    {
        _variant_t  vtValue;
        vtValue = m_Rec->Fields->GetItem(FieldName)->GetValue();
        FieldValue=vtValue.intVal;

       
    }

    CATCHERRGET

    sprintf(m_ErrStr,"Success");
    return 1;
}

Im using the below code to get the values.

AIErr getProjects()
{

    
    char buf[5000];
    int i;   
    std::string  catName;
    ::CoInitialize(NULL);
    Database db;
    Table tbl;
    errno_t err;
    err = fopen(&file,"c:\\DBResult.txt","w");
    fprintf(file, "Before Connection Established\n");
    //MessageBox(NULL,CnnStr,"Connection String",0);
    if(!db.Open(g->username,g->password,CnnStr))
    {
        db.GetErrorErrStr(ErrStr);
        fprintf(file,"Error: %s\n",ErrStr);
    }
    fprintf(file, "After Connection Established\n");

if(!db.Execute("select ProjectID,ProjectName from projectsample",tbl))

    {
        db.GetErrorErrStr(ErrStr);
        fprintf(file,"Error: %s\n",ErrStr);
    }

    int ProjectID;
    int UserID;
    int ProjectTitle;
    char ProjectName[ProjectNameSize];

    if(!tbl.ISEOF())
        tbl.MoveFirst();

    ProjectArrCnt=0;

    for(i=0;i<128;i++)
        buf='\0';
        int j=0;
   
    while(!tbl.ISEOF())
    {
        if(tbl.Get("ProjectID",ProjectID))
        {
            fprintf(file,"Project ID: %d ",ProjectID);
            ProjectInfo[ProjectArrCnt].ProjectID = ProjectID;

            sprintf(buf,"%d",ProjectID);
            //MessageBox(NULL, buf,"f ID", 0);
            j++;

        }
        else
        {
            tbl.GetErrorErrStr(ErrStr);
            fprintf(file,"Error: %s\n",ErrStr);
            break;
        }
        //if(tbl.Get("ProjectTitle",ProjectName))
        if(tbl.Get("ProjectName",ProjectName))
        {
           
            MessageBox(NULL,"Inside","",0);
            fprintf(file,"ProjectTitle: %s\n",ProjectName);

            //catName=CategoryName;

            ProjectInfo[ProjectArrCnt].ProjectName=ProjectName;
            //sprintf(buf,"%s",ProjectName);
            MessageBox(NULL,(LPCSTR)ProjectName,"",0);

        }
        else
        {
            tbl.GetErrorErrStr(ErrStr);
            fprintf(file,"Error: %s\n",ErrStr);
            break;
        }
        ProjectArrCnt++;
        //MessageBox(NULL, "While", "WIN API Test",0);
        tbl.MoveNext();
       
    }
    //MessageBox(NULL, ProjectInfo.ProjectName.c_str(),"f Name", 0);

    ::CoUninitialize();
    //sprintf(buf,"%s",file);
    //MessageBox(NULL,buf,"File",0);

    fprintf(file, "Connection closed\n");
   
    fclose(file);

    for(i=0;i<ProjectArrCnt;i++)
    {
        sprintf(buf,"%i",ProjectInfo.ProjectID);
        //MessageBox(NULL,buf,"Proj ID",0);
        //MessageBox(NULL,ProjectInfo.ProjectName.c_str(),"Project Name",0);
    }

    return 0;
}

In the above code im geeting project D which is an integer value. But not able to get the project name.

Please some one guide me.

This topic has been closed for replies.

1 reply

A. Patterson
Inspiring
May 5, 2009

As I said in the other thread, this really isn't the place to ask questions about a database API unrelated to the Illustrator SDK. You're far more like to find people familliar with your problem on a forum that is dedicated to answering those kinds of questions instead.