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();
                }   
                }

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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.