i want to do are the ff:

  • Loop through the Rows in the Datatable using Foreach or For

  • Compare every row data with the textbox value.

  • Once the value is matched or exists then break the loop & view a message.

. and i want view message is a confirm box ("record exist. do you want to continue?)
. if the user click yes it will save and if no close the confirm box.
. i dont know how to show a confirm box.pls help me.

  • if did not matched or not exists then save as new record
    & view a message(this message is an alert box only. and the showmessage is (successfully saved!.)
    . i already have a code in alert box..

    here's my code:

    getList() = inside code is stored procedure in sql server (list of all data)

    DataTable orgTb = maDDL.getList();

                    if (orgTb.Select() != null)
                            foreach (DataRow row in orgTb.Rows )
                                for (int i = 0; i < orgTb.Rows.Count; i++)
                                    string bu = orgTb.Rows[i]["bu_code"].ToString();
                                    string ar = orgTb.Rows[i]["area"].ToString();
                                    string desc = orgTb.Rows[i]["item_descr"].ToString();
                                    string dateIs = Convert.ToDateTime(orgTb.Rows[i]["date_issued"].ToString()).ToString();
                                    if (bu.ToString() == txtCode.SelectedValue.ToString() &&
                                        ar.ToString() == txtArea.SelectedValue.ToString() &&
                                        desc.ToString() == txtDesc.Text.ToString())
                                        if (Convert.ToDateTime(dateIs.ToString()).ToString()
                                        == Convert.ToDateTime(DI.SelectedDate).ToString())
                                            //confirm box
                                            //"record exist. do you want to continue?
                                        //alert box 
                                        //successfully saved!

pls.help me in this.

tnx in advance.

Edited by </scorpion>

3 Years
Discussion Span
Last Post by Mike Askew

Is this what you mean?

if (MessageBox.Show("record exist. do you want to continue?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
  //Do Something
  //Do something else

Edited by Fenrir()


no sir. :)

i want to loop through rows in datatable first,second compare it if exist(if exist then it will show a message else it will save as new record) thats what i mean sir. :)


I would have come up with the same as Fenrir() from looking at your code. The above is the correct code for your commented out section around a confirmation.

He just has omited code to save the record.


im sorry sir.. my mistake :)

but im not sure sir if c# have a (messagebox.show) .i try it many times..but it gives an error. can you help me in this.. pls. i try javascript in code behind as a confirm box.
here's my code.

 btnSubmit.OnClientClick = "if (confirm('Record already exist.do you want to continue?')) { PurgeCourse(); }";

but i want when i click submit button and if record exist then it will automatically show the confirmation box. in my code you will need to click again the button so that the message will show.


MessageBox.Show() requires it to be a WinForms project as far as I know (there could be ways around it like referencing the right DLLs)

I am starting to guess your project is console or service based?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.