2
I request a help to do the following, I do an Insert via Procedure after saving I want to fill the textbox with the id created so I can use it to associate to my item
I just need the order code to enter the textbox. Thanks for your help. New button event
private void btnNovoPedido_Click(object sender, EventArgs e)
{
try
{
int codigoCli = Convert.ToInt32(txtCodCliente.Text);
DateTime dtIni = DateTime.Now;
int idCliente = int.Parse(txtCodCliente.Text);
cc.pInserirPedido(0, dtIni, null, idCliente); //procedure para criar pedido
MessageBox.Show("Pedido gerado" );
}
catch (Exception ex)
{
MessageBox.Show("Erro:" + ex.Message);
}
}
ALTER PROC [dbo]. [pInserirPedido]
@decimal value (8,2),
@dtEntrada datetime,
@dtSaida datetime,
@idCliente int
as
Insert into TB_PEDIDOS(VAL_PEDIDO,
HOR_PEDIDO_ENTRADA,HOR_PEDIDO_SAIDA,ID_CLIENTE)
values(@valueTotal, @dtEntrate, @dtSaida, @idCliente)
IF @@ERROR<>0
--
SELECT -1
will return -1 if there is error
ELSE
SELECT MAX(ID_PEDIDIO) as 'CURRENT ORDER' FROM TB_PEDIDOS
GO
the last ID added
so I still don’t know how to get the value displayed in sql and play in the field
Where’s the Insert code? Where’s the button code?
– Rovann Linhalis
I added the new button event but I didn’t add the to put in the textbox because I don’t know how to make talusing Iqueryable but I don’t know how to use only I can use if the ID is in a grid ai so I recover the same value here: int code = Convert.Toint32(dgvCliente.CurrentRow.Cells[0].Value.Tostring()); txtCodigo.Text = code.Tostring(); example of a value I picked from the grid .
– Jameson
cc.pInserirPedido returns some value?
– Rovann Linhalis
Not only does it actually insert a new order so after I will add items to the order by another proc more so I need to receive the created order id
– Jameson
enter the code of
cc.pInserirPedido
– Rovann Linhalis
I put proc there in question
– Jameson
Is the database SQL Server? If it is, you have even considered using
SELECT @@Identity
how do PROC return? Something else, what is the type of the variablecc
?– Fernando
Ola Fernando CC is the instance of the class Conexaoclientedatacontext which I use to do anything in the database I am using LINQ to SQL classes . I didn’t try wouldn’t I use it after inserting ? how can I use it if I’m already searching about
– Jameson
I did what you advised in proc it is bringing the last id added but I am just checking in sql server the return of select more to implement in c# not yet because I do not know how to get the return of this select
– Jameson