Jump to content

Recommended Posts

Posted

Boas,

Estava agora a dar uma vista de olhos por um projecto que tenho e reparei agora que este código:

   Protected Sub btn_updatePT_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_updatePT.Click
    Dim con As New SqlConnection("Data Source=xxxxx\xxxx;Initial Catalog=xxxxx;User ID=xxxx;pwd=xxxx")
    con.Open()
    Dim command As New SqlCommand("UPDATE Pt SET PT_ID = @PT_ID, PT_Description = @PT_Description, AREA_ID = @AREA_ID FROM Pt INNER JOIN AREAS ON Pt.AREA_ID = AREAS.AREA_ID WHERE (Pt.PT_ID = @PT_ID)", con)
    command.Parameters.Add("@PT_ID", SqlDbType.VarChar).Value = txb_promotionID.Text
    command.Parameters.Add("@PT_Description", SqlDbType.VarChar).Value = txb_promotionDescription.Text
    command.Parameters.Add("@AREA_ID", SqlDbType.VarChar).Value = ddl_PTareaCode.SelectedValue

    command.ExecuteNonQuery()
    con.Close()
   End Sub

Não me está a fazer Update a todos os campos, mais propriamente não faz ao campos que estão com 'NULL', entretanto já tentei fazer com 'WHERE IS NULL' mas não consigo que ele faço o update desses campos, como posso proceder para fazer isso?

Obrigado

Posted

Mas o objectivo não é só atualziar a tabela Pt?

Não podia ser apenas:

UPDATE Pt SET PT_Description = @PT_Description, AREA_ID = @AREA_ID WHERE PT_ID = @PT_ID

Em relação à questão inicial, os campos que te referes são os restantes na tabela Pt?

Caso sejam, tens duas hipoteses

- incluir no UPDATE todos os campos

- ou definir na estrutura da tabela os valores default para os campos e indicar que não podem ter valor NULL

Posted

Espera lá, esta linha:

command.Parameters.Add("@AREA_ID", SqlDbType.VarChar).Value = ddl_PTareaCode.SelectedValue

está a passar para o parametro @AREA_ID o valor selecionado na dropdown ddl_PTareaCode.SelectedValue.

Não é esse valor que queres atualizar na tabela Pt?

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.