-2

I have created a class library which generates a number everytime i use it in any other Windows application and the number gets updated everytime i use it.

public int Generate_num(string P_PRM_TYPE)
{
    try
    {
        int v_last_no = 0;
        string query = @"select PARM_VALUE from soc_parm_mast where PARM_TYPE = '" + P_PRM_TYPE + "';";
        command.CommandText = query;
        OleDbDataReader reader = command.ExecuteReader();
        reader.Read();
        v_last_no = Int32.Parse(reader["PARM_VALUE"].ToString()) + 1;
        reader.Close();
        command.CommandText = @"update soc_parm_mast set PARM_VALUE = PARM_VALUE+1 where PARM_TYPE = " + P_PRM_TYPE + ";";
        command.ExecuteNonQuery();
        return v_last_no;
    }
    catch(Exception exception)
    {
        return 404;
    }
}

I am using this class in some other windows form application to generate a new no. everytime i call it.But it is not Working properly and is returning always 404.

int vTrans_no = GEN_NO.Generate_num("TRAN");
Smit Patel
  • 2,992
  • 1
  • 26
  • 44
A.Tiwari
  • 1
  • 3
  • As it is always returning 404, means your code is hitting a catch block. Can you give the exception details? – Sagar Jul 19 '16 at 12:34
  • Did you even try to debug it ? If yes then you should have known by now that why it is going in exception. If not do that first. – Akshay Jul 19 '16 at 12:34
  • is the connection managed by the class library hard coded into? or does it search connection string value from some config ? for example this library was builded for work with other apps, and its connection is retrived from the config of these apps.. in this case you should add the connection string in your app.config – Ciro Corvino Jul 19 '16 at 12:49

1 Answers1

0

There are missing quotes on the second query, P_PRM_TYPE is a string so you need to put ' ' like this :

command.CommandText = @"update soc_parm_mast set PARM_VALUE = PARM_VALUE+1 where PARM_TYPE = '" + P_PRM_TYPE + "';"
Steven
  • 896
  • 2
  • 16
  • 29
Anni
  • 1
  • 2