I am working on C# window form application, which do insert, update of data into the database.

I am having trouble, since I am new into this. I have declared temp variable that gets value if record exsits in the database. But in some scenarios if record is loaded onto the form temp variable will be 1, but if selection was changed from original to amendment the temp variable need to add 1 to the previous value and then save into the datbase with value for that field as 2. So I will have both records original and amended. If user add another amendment to same record datareader will read value as 2 and save as 3 on accept button click.

private void btnaccept_Click(object sender, System.EventArgs e)
        if (cmbcert.Text == "ORIGINAL")
                    cmd.Parameters.Add("@DOC_SEQ_NUM", SqlDbType.Char, 1).Value = 1;
                if (cmbcert.Text == "AMENDMENT")
                    cmd.Parameters.Add("@DOC_SEQ_NUM", SqlDbType.Char, 1).Value = tempdoc.Trim();
1 Year
Discussion Span
Last Post by tinstaafl

Assuming that tempdoc is a string that represents a number and that the record loaded is always the most recent version, one way to do this would be to cast the string as an integer, increment it then cast it back to a string. The Convert class would work well for this:

int tempNum = Convert.ToInt32(tempdoc.Trim()) + 1;
cmd.Parameters.Add("@DOC_SEQ_NUM", SqlDbType.Char, 1).Value = tempNum.ToString();

Edited by tinstaafl

This article has been dead for over six months. Start a new discussion instead.
Please be thoughtful and detailed and be sure to adhere to our posting rules.