Hello,
I'm pulling data into my datagridview table via sql. I want to generate more than the ID number in any row I choose and use it when creating a new record. Normally I can produce more of the last record I chose, but when I make a selection in any row, I want the highest value according to the ID number there. Hope I was able to explain my problem.
What I have tried:
i have tried this code
im using this code below the lines.
public void Code_Create()
{
Valuedetails u = new Valuedetails();
conn.Open();
SqlCommand comm = new SqlCommand("SELECT max(VALUEID) from VALUES_1 WHERE VALUEID=@VALUEID", conn);
comm.Parameters.Add("@VALUEID", SqlDbType.VarChar).Value = Variables.valueID;
u.ValueID = Convert.ToString(comm.ExecuteScalar());
conn.Close();
int kod = int.Parse(Regex.Replace(u.ValueID, "[^0-9]", "")) + 1;
string zeroStr = Regex.Replace(u.ValueID, "[^0-9]", "");
string newZeroStr = "";
for (int x = 0; x < zeroStr.Length; x++)
if (zeroStr[x] == '0') newZeroStr = newZeroStr + "0";
else { };
string newVal = Regex.Replace(u.ValueID, "[0-9]", "") + newZeroStr + kod;
txtvalueID.Text = newVal;
}
Program's view;
Code | Details
0001 | Pencil
0002 | Paper
0003 | Rubber
tk22 | Battery
tk23 | Glass
................
if i select
002 | Paper
, my code has to give new ID code
0004
, or select
tk22 | Battery
has to give me new record code
tk24