Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All
Actually I am not getting problem. I am trying to pass value from database as Previous Value(PreValue) and Current value carrying out from text box field(CurValue) and FieldValue is taking from database column name. I will just compare if PreValue not equal to CurValue then the record will be saved into table. I am not getting PreValue array format also. I am confused about that code. Actually I want to check value if any changes CurVale with PreVale then Loop will work else not. Anybody help me my mismatch.

C#
string[] PreValue = new string[] { Program.GetCharacterValue("Select FaName,MoName,Address,HasAE,Misuse from SCVBAE where FormSL='" + txtFrmSerial.Text.Trim() + "' AND PID='" + txtPID.Text.Trim() + "'") };

string[] FieldValue = new string[54] { "FaName","MoName","Address","HasAE","Misuse" };

string[] CurValue = new string[54] { txtFaName.Text, txtMoName.Text, txtAddress.Text, txtHasAE.Text, txtMisuse.Text };

            try
            {
                AEProperty Add = new AEProperty();
                Add.FormSl = txtFrmSerial.Text.Trim();
                Add.PID = txtPID.Text;

                for (int i = 0; i < 6; i++)
                {
                    if (PreValue[i].ToString() != CurValue[i].ToString())
                    {
                        Add.PreValue = PreValue[i].ToString();
                        Add.CurValue = CurValue[i].ToString();
                        Add.FieldName = FieldValue[i].ToString();
                        Add.FileNo = "1";
                        Add.ReasonADT = "Punching error";
                        Add.UpdateBy = Program.EnterBy;
                        Add.UpdateDt = DateTime.Today.ToString("MM/dd/yyyy");
                        Add.UpdateTm = DateTime.Now.ToString("HH:mm:ss tt");

                        DSDBHandler AddHandler = new DSDBHandler();
                        AddHandler.AddADT(Add);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Record cannot insert ! check properly" + ex.Message);
                txtFrmSerial.Focus();
            }
Posted
Updated 24-Mar-14 21:03pm
v3
Comments
syed shanu 25-Mar-14 0:29am    
Did you check with break Point.Debug ur program line by line using break point.
I dont understant what you have in arrays .here string[] PreValue = new string[] you use like this and for rest string[] CurValue = new string[54] and in your for loop for (int i = 0; i < 55; i++)
it seems ur getting error at this miss counts.What error you get.

Within the loop, look at this line:
C#
Add.FieldName = FieldValue[i].ToString();
FieldValue[i] can have a maximum i of 5, since that's the largest integer that still conforms the loop condition i < 6.

But FieldValue[5] doesn't exist. FieldValue has 5 members. Arrays are "zero-based" in C# and therefore range from 0 to 4.

How to solve that I have no idea, since I don't know what that code should do. I'm baffled by the arrays FieldValue and CurValue being both declared with 54 items, but having only 5 defined.


[Edit]
I just checked with VS2008. The declarations of FieldValue and CurValue don't even compile.

Drop both occurances of "54". Then, use one of them as loop boundary:
C#
string[] FieldValue = new string[] { "FaName","MoName","Address","HasAE","Misuse" };
 
string[] CurValue = new string[] { txtFaName.Text, txtMoName.Text, txtAddress.Text, txtHasAE.Text, txtMisuse.Text };

// [..]

    for (int i = 0; i < FieldValue.Length; i++)
    {

[/Edit]
 
Share this answer
 
v2
Comments
Member 10602440 25-Mar-14 8:29am    
You are right but i am not able to defined PreValue into loop and can you assured that loop is correct if I change value 5 instead of 6.
lukeer 25-Mar-14 8:46am    
I updated my solution.
Member 10602440 25-Mar-14 9:21am    
Thanks for continue with me. It's good. But now i am facing problem on PreValue string. I think my declaration not correct for array. How can I read value from database one by one.
lukeer 25-Mar-14 9:39am    
I'm of no help when it comes to databases. Do as syed shanu told you: Use your debugger. That way you can check what PreValue is initialized to and, if you have access to the source, how it is obtained.
Index will go from 0 to 53 as you are having 54 items in each array.
change your loop from :
for (int i = 0; i < 55; i++)

to
for (int i = 0; i < 54; i++)

else it will catch out of bound exception.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900