I wanted the textbox with the information about that student to be filled in with the student's MR (primary key).
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'mtryingthiswaybutit'snotworking.
SqlConnectioncon=newSqlConnection(@"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;
}