C/Visual C - no entra los datos

 
Vista:
sin imagen de perfil
Val: 3
Ha aumentado su posición en 15 puestos en C/Visual C (en relación al último mes)
Gráfica de C/Visual C

no entra los datos

Publicado por Daniela (2 intervenciones) el 22/02/2018 14:09:50
cuando realizo el paso a paso se salta lo que contiene el while

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
string consulta = @"select almacen,RefTallaColor,Referencia,Talla,color,IDCurva,CantUnidades,CantModificadas from Analisis_Curva  WHERE RefTallaColor = '" + ddlReferenciaTallaColor.SelectedValue + "' and almacen  = '" + ddlAlmacen.SelectedValue + "'";
var cmd = new SqlCommand(consulta, conexion);
SqlDataReader lector = cmd.ExecuteReader();
while (lector.Read())
{
    var customers = new CustomersBe();
    customers.Almacen = (string)lector[0];
    customers.reftallacolor = (string)lector[1];
    customers.referencia = (string)lector[2];
    customers.talla = (string)lector[3];
    customers.color = (string)lector[4];
    customers.idcurva = (int)lector[5];
    customers.CantUnidades = (string)lector[6];
    customers.CantModificadas = (string)lector[7];
 
    lista.Add(customers);
}
grvAnalisis.DataSource = lista;
grvAnalisis.DataBind();
conexion.Close();
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 60
Ha mantenido su posición en C/Visual C (en relación al último mes)
Gráfica de C/Visual C

no entra los datos

Publicado por Yamil Bracho (26 intervenciones) el 22/02/2018 14:32:52
Tu consulta a la BD no esta trayendo registros
Cuando hagas el paso a paso captura el valor de "consulta" y ejecutala en SQL Server a ver que te trae...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Alexbd
Val: 4
Ha mantenido su posición en C/Visual C (en relación al último mes)
Gráfica de C/Visual C

no entra los datos

Publicado por Alexbd (2 intervenciones) el 22/02/2018 16:26:50
Hola estuve leyendo y encontre un articulo que puede servir https://support.microsoft.com/en-us/help/311274/how-to-handle-multiple-results-by-using-the-datareader-in-visual-c-net

Y aqui otro ejemplo
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
SqlDataReader getSqlDataReader(String ^_sql)
{
    SqlDataReader ^_sqlDataReader = nullptr;
 
    SqlConnection ^_connection = gcnew SqlConnection();
 
    ConnectionStringSettings ^connectionSettings = ConfigurationManager::ConnectionStrings["AppDefaultConnection"];
    this->_connection->ConnectionString = connectionSettings->ConnectionString;
 
    try {
        this->_connection->Open();
    }
 
    catch (Exception ^_exception)
    {
        Console::WriteLine("Error : "  + _exception->Message);
        return nullptr;
    }
 
    try
    {
        SqlCommand ^_sqlCommand = gcnew SqlCommand(_sql,_connection);
        _sqlDataReader = _sqlCommand->ExecuteReader();
    }
 
    catch(Exception ^_exception)
    {
        Console::WriteLine("Error : "  + _exception->Message);
        return nullptr;
    }
 
    return _sqlDataReader;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
SqlDataReader ^reader = getSqlDataReader(yourParameterizedQueryString);
 
        List<TypeToFetch>^ data = gcnew List<TypeToFetch^>();
        if(reader != nullptr && reader->HasRows)
        {
            TypeToFetch^ typeToFetch = gcnew TypeToFetch();
            while(reader->Read())
            {
                    // example
                TypeToFetch->id = (int) reader["Id"];
                TypeToFetch->name = reader["Name"]->ToString();
                data->Add(typeToFetch);
            }
        }
Fuente : https://stackoverflow.com/questions/22959665/connect-and-query-database-in-managed-c-using-sqlconnection

Este otro usa VB .NET hace uso de NextResult deberias probar asi

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
Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Windows.Forms
Imports System.Data.SqlClient
 
 
Public Class MainClass
    Shared Dim WithEvents con As SqlConnection
 
    Shared Sub Main()
        con = New SqlConnection("Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI")
 
        Dim cmd As New SqlCommand()
 
        cmd.CommandText = "SELECT * FROM Employee; SELECT * FROM Employee"
        cmd.Connection = con
 
        Try
            con.Open()
            Dim reader As SqlDataReader = cmd.ExecuteReader()
            Do
                While reader.Read()
                    Console.WriteLine(reader(0) & vbTab & reader(1))
                End While
            Loop While reader.NextResult()
 
            reader.Close()
        Finally
            con.Close()
        End Try
    End Sub
End Class
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar