5
Reply

Array Over size Problem

Zeb Rehman

Zeb Rehman

Dec 8 2011 5:25 PM
1.2k
Hello everybody,
  When i run the following code it give me the error which is also given below. I think there is problem of Array size. Can somebody please tell me how can i remove this error. My main goal is to save the value from database to array.
 Thanks


using System;
using System.Data.OleDb;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _2
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {
  try
  {
  int count = 0;
  string[] name = null;
  string[] address = null;
  string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\\ptcl.accdb";

  OleDbConnection conn = new OleDbConnection(connectionString);

  string sql = "SELECT * FROM 51";

  OleDbCommand cmd = new OleDbCommand(sql, conn);
  {
  conn.Open();
  OleDbCommand com = new OleDbCommand(sql, conn);
  OleDbDataReader dr = com.ExecuteReader();
  while (dr.Read())
  {
  name[count] = dr.GetString(1).ToString();
  //textBox1.Text = count.ToString() ;
  //count++;
  }
  conn.Close();
  }
  }
 
 
  catch (Exception ex)
  { MessageBox.Show(ex.ToString());}
  }
  }
}


Answers (5)