none
How to delete row with specified parameters? RRS feed

  • Question

  • I have mydb and Customers table in it, with Name and Password columns.Now i want to delete row, where Name="artxach".Please help me to do it.... 
    Thursday, January 6, 2011 8:03 AM

Answers

  • Hello artxach,

     

    Welcome to the MSDN Forum and thank you for posting here.

    Based on your issue, if you want to use ADO.NET to delete a row, please try to read this article.

    http://www.codeproject.com/KB/database/simpledbreadwrite.aspx

    If you want to use Entity Framework, the following codes will help you:(DataBase: School, Table: Course)

                 using (SchoolEntities ctx = new SchoolEntities())
                {
                    Course c = ctx.Course.SingleOrDefault<Course>(new Func<Course, bool>((Course) =>
                        {
                            if (Course.CourseID == 1047)
                                return true;
                            return false;
                        }
                        ));
                    ctx.Course.DeleteObject(c);
                    ctx.SaveChanges();
                }

    Hope it can help you,

    If you have any questions, please feel free to let me know,

    Best Regards,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 10, 2011 9:50 AM
    Moderator

All replies

  • Hello artxach,

     

    Welcome to the MSDN Forum and thank you for posting here.

    Based on your issue, if you want to use ADO.NET to delete a row, please try to read this article.

    http://www.codeproject.com/KB/database/simpledbreadwrite.aspx

    If you want to use Entity Framework, the following codes will help you:(DataBase: School, Table: Course)

                 using (SchoolEntities ctx = new SchoolEntities())
                {
                    Course c = ctx.Course.SingleOrDefault<Course>(new Func<Course, bool>((Course) =>
                        {
                            if (Course.CourseID == 1047)
                                return true;
                            return false;
                        }
                        ));
                    ctx.Course.DeleteObject(c);
                    ctx.SaveChanges();
                }

    Hope it can help you,

    If you have any questions, please feel free to let me know,

    Best Regards,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 10, 2011 9:50 AM
    Moderator
  • Hello artxach,

    How was your issue? Did you solve it? 

    Because your thread has lasted for a long time, I will close it for you by marking an answer. If you have anything you need or you would like to re-open it , you can unmark or you can post a thread another.

    Thank you for you understanding and support!

     

    Happy everyday!


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 17, 2011 7:40 AM
    Moderator