0
The event Cadastrar
is appearing with the error.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CamadaModelo;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using CamadaControle;
namespace CamadaControle
{
public class ctlTarefas
{
public bool Cadastrar(mdlTarefas _mdlTarefas)
{
try
{
string conexaoMSAccess = ConfigurationManager.ConnectionStrings["conexaoMSAccess"].ToString();
OleDbConnection conexaodb = new OleDbConnection(conexaoMSAccess);
conexaodb.Open();
string query = "INSERT INTO tbl_tarefas (nome, descrição, data) VALUES (@Nome, @Descrição, @Data)";
OleDbCommand cmd = new OleDbCommand(query, conexaodb);
var pmtNome = cmd.CreateParameter();
pmtNome.ParameterName = "@Nome";
pmtNome.DbType = DbType.String;
pmtNome.Value = _mdlTarefas.nome;
cmd.Parameters.Add(pmtNome);
var pmtDescricao = cmd.CreateParameter();
pmtDescricao.ParameterName = "@Descrição";
pmtDescricao.DbType = DbType.String;
pmtDescricao.Value = _mdlTarefas.nome;
cmd.Parameters.Add(pmtDescricao);
var pmtData = cmd.CreateParameter();
pmtData.ParameterName = "@Data";
pmtData.DbType = DbType.String;
pmtData.Value = _mdlTarefas.nome;
cmd.Parameters.Add(pmtData);
if(cmd.ExecuteNonQuery() > 0)
{
conexaodb.Close();
return true;
}
else
{
conexaodb.Close();
return false;
}
}
catch(Exception ex)
{
Console.WriteLine("Erro ao inserir informações!" + ex.Message);
}
finally
{
Console.WriteLine("Precione inicio");
Console.ReadKey();
}
}
}
}
Please adjust your question. It has formatting flaws. Put the error in text and not image.
– Tiedt Tech
Adjusted, thanks for the tip
– Patryck Dalpont
@Patryckdalpont The answer solved your question? Do you think you can accept it? See [tour] if you don’t know how to do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero