declare variable escalar C# Ayuda por favor
Publicado por Erick (1 intervención) el 22/11/2018 07:57:20
estoy tratando de ejecutar este código para hacer una busquedad pero me sale error, diciendo declare variable escalar "@id"
trato de hacer una consulta obteniendo el id al seleccionar un dato del contenido de datagridview haciendo clic a un boton y hacer la consulta que especifico aquí abajo con un parámetro que es el id@
y esto es en el boton
trato de hacer una consulta obteniendo el id al seleccionar un dato del contenido de datagridview haciendo clic a un boton y hacer la consulta que especifico aquí abajo con un parámetro que es el id@
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public Boolean mostrarmedicosxespecialidad(int medicoid)
{
try
{
using (SqlConnection cn = new SqlConnection())
{
cn.ConnectionString = ConfigurationManager.ConnectionStrings["cnMedika"].ConnectionString;
cn.Open();
using (SqlCommand cm = new SqlCommand())
{
String cad =
"select tm.medico id,tm.Nombres+','+tm.Apellidos as 'Nombres del Médico'" +
" from tbMedicos tm,tbEspecialidades te" +
" where tm.Especialidad=te.IdEspecialidad and tm.Especialidad= @id ";
cm.Connection = cn;
cm.CommandType = CommandType.Text;
cm.CommandText = cad;
cm.Parameters.AddWithValue(" @id ", medicoid+"");
using (SqlDataAdapter da = new SqlDataAdapter(cad, cn))
{
DataTable dr = new DataTable();
da.Fill(dr);
dgvlistaMedicos.DataSource = dr;
}
int filasAfectadas = cm.ExecuteNonQuery();
if (filasAfectadas > 0) return true; else return false;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Nota");
return false;
}
}
y esto es en el boton
1
2
3
4
5
int indiceFilaSeleccionada = dgvlistaEspe.CurrentRow.Index;
string valorId = dgvlistaEspe.Rows[indiceFilaSeleccionada].Cells[0].Value.ToString();
int idmedico = Convert.ToInt32(valorId);
mostrarmedicosxespecialidad(idmedico);
Valora esta pregunta


0