i am getting the error "index was outside the bounds of the array" when running the program, idk why. I am not able to find the issue.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
enter code here
namespace WebService
{
public class DataHelper
{
public static SqlConnection GetConnection()
{
SqlConnection con = new SqlConnection("Integrated Security = True; Server = localhost; Trusted_Connection= yes; database= Programkonstruktion; ");
con.Open();
return con;
}
//Create new method to get CustomerInfo
public static List<String[]> getCustomerInfo(int CustId)
{
List<String[]> lista = new List<string[]>();
using (SqlConnection con = GetConnection())
{
//SQLCommand
SqlCommand cmd = new SqlCommand("Select * From Customer", con);
//To read from SQL Server
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string[] row = new string[dr.FieldCount];
for (int i = 0; i < dr.FieldCount; i++)
{
row[i] = dr.GetValue(i + 1).ToString();
}
lista.Add(row);
}
return lista;
}
}
I am happy for all the answers you can give me! best regards } }