-1
I’m trying to get an insight into my comics of a college app I’m developing. However, I’m having difficulties.
Taking the values of the texbox
protected void button1_cad_cliente(object sender, EventArgs e)
{
Clientes cl = new Clientes();
cl.Nome = nome_clientes.Text;
cl.Cpf = Convert.ToInt32(cpf_clientes.Text);
cl.Rg = Convert.ToInt32(rg.Text);
cl.Endreco = endereco.Text;
cl.Email = email_clientes.Text;
ClienteDAL.cadastra(cl);
}
DAL that performs the Insert or at least this is the intention
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Geax.Model;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Geax.DAL
{
public class ClienteDAL
{
public static void cadastra(Clientes obj)
{
Conexao conn1 = new Conexao();
conn1.AbrirConexao();
String InsertCliente = ("INSERT INTO tab_cliente (nome,cpf,rg,endereco,telefone,email) VALUES('Cl.Nomes','Cl.Cpf','Cl.Rg','Cl.Endereco','Cl.Telefone','Cl.Email')");
MySqlCommand cmd = new MySqlCommand(InsertCliente);
cmd.ExecuteNonQuery();
}
}
}
Class connecting to the bank:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Geax.DAL
{
public class Conexao
{
private static MySqlConnection objConexao = null;
private String conn_db = "server=localhost; Database=xpto; User=root; Password='';";
public void AbrirConexao()
{
objConexao = new MySqlConnection();
objConexao.ConnectionString = conn_db;
objConexao.Open();
}
}
}
protected void button1_cad_cliente(object sender, EventArgs e)
{
Clientes cl = new Clientes();
cl.Nome = nome_clientes.Text;
cl.Cpf = Convert.ToInt32(cpf_clientes.Text);
cl.Rg = Convert.ToInt32(rg.Text);
cl.Endreco = endereco.Text;
cl.Email = email_clientes.Text;
ClienteDAL.cadastra(cl);
}
How have I tried to associate the cmd.Parameters.AddWithValue("@nome", stringComNome);
with the data I picked up.
Pus: cmd.Parameters.AddWithValue("@nome", nome_clientes.txt);
but does not recognize
Does not perform Insert and an error appears
– Vinícius
Error that appears when trying to insert: http://i.imgur.com/V03zjdm.png
– Vinícius
Paul, in the way
cadastra(Clientes obj)
you define theobjeto
ofClientes
by nameobj
, but starts usingC1.nome
,C1.cpf
... Wouldn’t that be the mistake?– Gustavo Cinque