开发者

How to increment the string value during run time without using dr.read() and store it in the oledb db?

Here is my code, everything is working fine the only problem is with the ReadData() method in which i want the string value to be increment i.e AM0001,AM0002,AM0003 etc. This is happening till the execution of the program once i stop the execution of program, the second time when i run the program the same value i.e AM0001 is getting return. Due to this i am getting a error from oledb because of AM0001 is a primary key field.

This is my code:

class Jewellery : Connectionstr
{

    string lmcode;
    public string LM_code
    {
            get { return lmcode;}
            set { lmcode = ReadData();}
    }

    string mname;
    public string M_Name
    {
        get { return mname; }
        set { mname = value;}
    }

    string desc;
    public string Desc
    {
        get { return desc; }
        set { desc = value; }
    }


    public string ReadData()
    {
        string jid = string.Empty;
        string displayString = string.Empty;
        String query = "select max(LM_code)from Master_Accounts";
        Datamanager.RunExecuteReader(Constr,query);

          jid = LM_code;// this is working on first execution, the second time when i run the program the value null defined in LM_code.
          if (string.IsNullOrEmpty(jid))
            {
                jid = "AM0000";//This string value has to increment at every time, but it is getting increment only one time.
            }
            int len = jid.Length;
           开发者_Python百科 string split = jid.Substring(2, len - 2);
            int num = Convert.ToInt32(split);
            num++;
            displayString = jid.Substring(0, 2) + num.ToString("0000");
            return displayString;
    }

    public void add()
    {


           String query ="insert into Master_Accounts values ('" + LM_code + "','" + M_Name + "','" + Desc + "')";
           Datamanager.RunExecuteNonQuery(Constr , query);
    }

Any help will be appreciated.


Do not declare jid in method, declare it in class level:

private string jid  = string.Empty;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜