How to increment the string value during run time without using dr.read() and store it in the oledb
- by sameer
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 but only one time the value is getting increment to AM0001, the second time 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.
enter code here:
class Jewellery : Connectionstr
{
string lmcode = null;
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);
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;
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.