I'm learning a programming language and I set out to develop a budgeting program. My first hurdle is being to add the values of the primary keys in the foreign keys of the respective tables. This code below works well for this, but after copying the PK from the Customer table to FK from the Budget table, the next data always adds to the following table rows and not to the current row as it should be. can anybody help me? Here's a snippet of my code:
connect.Open();
OleDbCommand cmd1= new OleDbCommand("INSERT into Cliente(nome, endereco)"+"Values (@nome, @endereco)", connect); // nome e endereço
OleDbCommand cmd2 = new OleDbCommand("INSERT into Produto(nome, preco)" + "Values (@nomeProd, @precoProd)", connect); //produto, preço
OleDbCommand cmd3 = new OleDbCommand("INSERT into Orcamento(id_cliente) SELECT MAX(id) FROM Cliente", connect);
//Como eu faria para adicionar a informação "data" que está numa string no objeto acima, como as demais (cmd1 e cmd2) tendo em vista que existe o comando SELECT?
if(connect.State == ConnectionState.Open)
{
cmd1.Parameters.Add("@nome",OleDbType.Char,20).Value = nome;
cmd1.Parameters.Add("@endereco",OleDbType.Char,20).Value = endereco;
cmd2.Parameters.Add("@nome", OleDbType.Char, 20).Value = nomeProd;
cmd2.Parameters.Add("@preco", OleDbType.Char, 20).Value = precoProd;
cmd3.Parameters.Add("@id_cliente", OleDbType.Char, 20).Value = "";
cmd3.Parameters.Add("@data", OleDbType.Char, 20).Value = data;
try
{
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
cmd3.ExecuteNonQuery();