
Como puedo mostrar datos de una bd de tipo int32 en un listviewitem
Publicado por Kevin Alcala Ruiz (5 intervenciones) el 23/04/2015 10:06:50
//No me deja ejecutar el programa porque me dice que no se puede convertir un tipo system.int32 al tipo string, en la base de datos el nombre y el codigocliente estan entrados como texto pero el clienteID y la compañiaID no estan como int, no se como hacer para mostrarlos en el listviewitem, perdonen pero soy nuevo en esto y la verdad que no se como solucionarlo. Muchas gracias, salu2.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.ComponentModel;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;namespace PogramaNomCodi
{ public partial class Form1 : Form {public Form1()
{InitializeComponent();
}private string cadenaConexio = ProgramaNomCodi.Properties.Settings.Default.ConnectionString;
private SqlConnection CN;
private SqlCommand CMD;
private SqlDataReader RDR;
private void btnCargar_click(object sender, EventArgs e)
{lvContactos.Items.Clear();
CN = new SqlConnection(cadenaConexio);
CMD = new SqlCommand("SELECT [ClienteID], [CompaniaID], [CodigoCliente], [Nombre] FROM [v_Cliente] WHERE ClienteID = 2;", CN);
CMD.CommandType = CommandType.Text;
try
{CN.Open();
RDR = CMD.ExecuteReader();
while (RDR.Read())
{ListViewItem lvi = new ListViewItem();
lvi.Text = (string)RDR["CodigoCliente"].ToString();
lvi.SubItems.Add((string)RDR["Nombre"]);
lvi.SubItems.Add((string)RDR["CompaniaID"]);
lvi.SubItems.Add((string)RDR["ClienteID"]);
lvContactos.Items.Add(lvi);
} }catch (Exception ex)
{MessageBox.Show(ex.Message);
}finally
{CN.Close();
} }private void Form1_Load(object sender, EventArgs e)
{ }private void btnInforme_click(object sender, EventArgs e)
{ } }}Valora esta pregunta


0





