0
He wanted the MRI of the student (primary key) to be filled the textbox with the information related to that student.
CREATE TABLE ALUNO(
RM_ALUNO INT NOT NULL,
NM_ALUNO VARCHAR (40) NOT NULL,
SERIE_ALUNO VARCHAR (30) NOT NULL,
DTNASC_ALUNO DATE NOT NULL,
PERIODO VARCHAR(50) NOT NULL,
CURSO VARCHAR(50) NOT NULL,
RG_RESPON_ALUNO_1 CHAR (11) NULL,
NM_RESPON_ALUNO_1 VARCHAR (40) NULL,
TEL_RESPON_ALUNO_1 VARCHAR(40) NULL,
RG_RESPON_ALUNO_2 CHAR (11) NULL,
NM_RESPON_ALUNO_2 VARCHAR (40) NULL,
TEL_RESPON_ALUNO_2 VARCHAR(40) NULL,
RG_RESPON_ALUNO_3 CHAR (11) NULL,
NM_RESPON_ALUNO_3 VARCHAR (40) NULL,
TEL_RESPON_ALUNO_3 VARCHAR(40) NULL,
RG_RESPON_ALUNO_4 CHAR (11) NULL,
NM_RESPON_ALUNO_4 VARCHAR (40) NULL,
TEL_RESPON_ALUNO_4 VARCHAR(40) NULL,
RG_RESPON_ALUNO_5 CHAR (11) NULL,
NM_RESPON_ALUNO_5 VARCHAR (40) NULL,
TEL_RESPON_ALUNO_5 VARCHAR(40) NULL,
PRIMARY KEY (RM_ALUNO),
)
I’m trying this way but it’s not working.
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-SEFSOUP\SQLEXPRESS;Initial Catalog=DISPENSA;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select * from ALUNO where RM_ALUNO=" + txtRm.Text, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@NM_ALUNO", SqlDbType.VarChar).Value = nome;
cmd.Parameters.Add("@SERIE_ALUNO", SqlDbType.VarChar).Value = serie;
cmd.Parameters.Add("@PERIODO_ALUNO", SqlDbType.VarChar).Value = periodo;
cmd.Parameters.Add("@CURSO_ALUNO", SqlDbType.VarChar).Value = curso;
lblAluno.Text = nome;
lblSerie.Text = serie;
lblPeriodo.Text = periodo;
lblCurso.Text = curso;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
da.Dispose();
cmd.Dispose();
con.Close();
if (dt.Rows.Count == 1)
{
return true;
}
else
{
return false;
}
return ok;
}
Hello @Leticia. Pf more detail your question. If possible, put the code you have already tried to use to reach your goal.
– João Martins
@Leticiacristina, You are already making the connection to the database in your application?
– Leandro Angelo
Leticia: do not use
SELECT *
but enter the name of the columns you need to fill the screen; this reduces network traffic and other advantages.– José Diz
I’m using all the information on the screen, I’m not getting the information to pass to the label
– Leticia Cristina
@Leticiacristina first check if your select is really bringing the data you want
– gabrielfalieri
Detail, with this da.Fill(dt) this is code to fill the datagrid of c#, never it will appear in a label like this... You don’t even have a datagridview in your form
– gabrielfalieri