2
A small problem appeared, which in my old application worked normally.
My DAL Class, is not connecting in Mysql. Since all the connection parameters, I believe it is correct.
My DAL who makes the connection.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Geax1.Model;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Geax1.DAL
{
public class VeiculosDAL
{
public static void cadastra(_Veiculos obj)
{
using (var conn = new MySqlConnection("server=127.0.0.1;Database=xpto;User ID=root;Password='';"))
{
try
{
conn.Open();
String InsertVeiculos = ("INSERT INTO tab_veiculo (placa,quilometragem,cor,tipo,ano,chassi,modelo) VALUES(@placa, @cor, @tipo, @ano, @chassi, @modelo)");
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = InsertVeiculos;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@placa", obj.Placa1);
cmd.Parameters.AddWithValue("@quilometragem", obj.Quilometragem1);
cmd.Parameters.AddWithValue("@cor", obj.Cor1);
cmd.Parameters.AddWithValue("@tipo", obj.Tipo1);
cmd.Parameters.AddWithValue("@ano", obj.Ano1);
cmd.Parameters.AddWithValue("@chassi", obj.Chassi1);
cmd.Parameters.AddWithValue("@modelo", obj.Modelo1);
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
}
}
}
}
Note: My WAMP is on.
Check it out: https://github.com/brunoocasali/DataRepository is a repository to help you write these connection classes with the database in a simpler way:D
– Bruno Casali