I'm trying to make a DataTable
that saves data (I'm not using database) referring to the name and email of a client and displays in a DataGridView
(display on the grid is not the problem, this I know do) the data that was typed in textbox
.
I started messing with DataTable
yesterday and read that it is better for my application than a List<T>
, which I have already used to do addition and deletion in a signup program.
Below I put the code of the Data class and its attributes and methods, but I would like to get help to understand how to get the method of my class (which in this case is the Name that is typed in the text box txt_nome
Email
that is received in txt_email
) and put it inside DataTable
. Below I put the parts of the code that I already have and are relevant:
public partial class Form1 : Form
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("Cadastro");
..........
private void bt_salvar_Click_1(object sender, EventArgs e)
{
DataRow dr = dt.NewRow();
dr["Nome"] = txt_nome.Text;
dt.Rows.Add(dr);
ds.Tables.Add(dt);
dataGridView1.DataSource = dt;
}
...............
public class Dados
{
private string _nome;
private string _email;
//construtor para iniciar os dados privados - recebe parametros
public Dados(string nome, string email)
{
this._nome = nome;
this._email = email;
}
public string Nome
{
get
{
return _nome;
}
set
{
_nome = value;
}
}
public string Email
{
get
{
return _email;
}
set
{
_email = value;
}
}
}
If I'm talking about some nonsense I'm sorry, I'm a beginner and I'm trying to learn everything very well (I'm looking for several points of view on each subject of C #).