I'm trying to make an insert in my bd from an app from the college I'm developing. However, I'm having difficulties.
Getting the texbox values
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 performing the insert or at least that 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 that connects 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);
}
I have already tried to associate cmd.Parameters.AddWithValue("@nome", stringComNome);
with the data I got above.
Pus: cmd.Parameters.AddWithValue("@nome", nome_clientes.txt);
but does not recognize