none
some question in asp.net when i use listview RRS feed

  • 问题

  •  I insert a listview into a page which i designed and link the access database. I have finished the "insert data" and "edit data" functions, but when i want to delete one row in the listview, i got a problem that it doesn't work. Can any one help to fix it? The code is as following:

    if

    (e.CommandName == "Delete")

    {

    Label IDLabel1 = (Label)e.Item.FindControl("IDLabel1");

    string deleteCommand = "DELETE FROM [DataofID] WHERE ID=" + Convert.ToInt32(IDLabel1.Text);

    AccessDataSource1.DeleteCommand = deleteCommand;

    AccessDataSource1.DataBind();

    }

    2012年7月2日 8:38

答案

  • Problem solved. I changed the code:

    SelectCommand="SELECT * FROM [DataofWWID]" ConflictDetection="CompareAllValues"  to

    SelectCommand="SELECT * FROM [DataofWID]" ConflictDetection="OverwriteChanges" 

    2012年7月4日 1:34

全部回复

  • Hi:-)

    Do this——

    AccessDataSource1.DeleteCommand = deleteCommand;

    AccessDataSource1.DeleteCommand.ExecuteNonQuery();  //Add this!

    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    2012年7月2日 9:17
  • Hi, thx for your response. I have tried your method, but it still doesn't work. Am i missing some definition or using? Thx again.
    2012年7月3日 0:54
  • Hi:-)

    Do this——

    AccessDataSource1.DeleteCommand = deleteCommand;

    AccessDataSource1.DeleteCommand.ExecuteNonQuery();  //Add this!

    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    I have a "insert" function which runs smoothly. Code is as following:

    if

    (e.CommandName == "Insert")

    {

    Label IDLabel1 = (Label)e.Item.FindControl("IDLabel1");

    TextBox widTextBox = (TextBox)e.Item.FindControl("widTextBox");

    TextBox First_NameTextBox = (TextBox)e.Item.FindControl("First_NameTextBox");

    TextBox Last_NameTextBox = (TextBox)e.Item.FindControl("Last_NameTextBox");

    TextBox ScoreTextBox = (TextBox)e.Item.FindControl("ScoreTextBox");

    string insertCommand = "INSERT INTO [DataofID] ([WID], [First Name], [Last Name], [Score]) VALUES ('" + widTextBox.Text + "', '" + First_NameTextBox.Text + "', '" + Last_NameTextBox.Text + "', '" + ScoreTextBox.Text + "')";

    AccessDataSource1.InsertCommand = insertCommand;

    AccessDataSource1.DataBind();

    2012年7月3日 1:05
  • Problem solved. I changed the code:

    SelectCommand="SELECT * FROM [DataofWWID]" ConflictDetection="CompareAllValues"  to

    SelectCommand="SELECT * FROM [DataofWID]" ConflictDetection="OverwriteChanges" 

    2012年7月4日 1:34