Jump to content
Joaanaa.93

[Resolvido] Delete Rows

Recommended Posts

Joaanaa.93

Bom dia pessoal, estou a acabar um web site, e estou na rate do backoffice, mas não consigo apagar a informação que pretendo

Estou a tentar eliminar assim:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace WebApplication23.Backoffice
{
   public partial class WebForm3 : System.Web.UI.Page
   {
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
	    SqlConnection sqlConn = new SqlConnection();
	    sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["inovaConn"].ConnectionString;
	    SqlDataSource1.DeleteCommand = "DELETE FROM Revistas_Detail FROM Revistas_Detail INNER JOIN Revistas_Header ON Revistas_Detail.nr_revista = Revistas_Header.nr_revista WHERE (Revistas_Detail.nr_revista = @nr_revista) AND (Revistas_Header.nr_revista = @nr_revista)";

	    sqlCommand.Parameters.AddWithValue("@nr_revista", GridView1.DataKeys.ToString());
	    SqlDataSource1.SelectParameters["@nr_revista"], GridView1.DataKeys.ToString();
	    sqlCommand.Connection = sqlConn;
	    sqlConn.Open();

	    sqlCommand.ExecuteNonQuery();

    }
   }
}

e ele ao clicar no "Delete" devia de apagar:

http://gyazo.com/c1ec23d44ff399868aabb6a6a973129f

Comprimentos

Share this post


Link to post
Share on other sites
pikax

O melhora o teu query:

DELETE FROM Revistas_Detail WHERE (Revistas_Detail.nr_revista = @nr_revista)

Edited by pikax

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.