title: Excel Data to Data Grid View in vb6
body: <p>Hi everybody I am new!</p>
  
  <p>So, I was developing a simple software with VB 6.0 (yeah, i know quite old). I had to do is manipulate Ms Excel sheet into VB Application. The actual task is to display the data or tables (whatever we call it)provided in the Excel sheet into Data Grid View.</p>
  
  <p>I am using ADODB. Here is the code:</p>
  
  <pre><code>  Dim file_name As String
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
   cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; _
   file_name &amp; ";Extended Properties=Excel 12.0;"
  
   If cn.State = adStateOpen Then
       MsgBox "Excel File is Connected. ", , "Message"
       rs.CursorLocation = adUseClient
       rs.Open "SELECT * FROM [Sheet1$]", cn, 3, 3, 1 - adCmdText
       Set DataGrid1.DataSource = rs
       DataGrid1.Refresh
       DataGrid1.ReBind
  
    Else: MsgBox "Error: Excel File is not Connected. ", , "Message"
   End If
   rs.Close
   cn.Close
  </code></pre>
  
  <p>But I am facing a problem! Now the excel data is shown in Data Grid Control. But immediately the data is erased after the execution of the Line "rs.close". I am giving a snapshot.</p>
  
  <p>Please Help. Thank you...</p>
  
  <p>Here is the image:
  <img src="https://i.stack.imgur.com/yohkj.png" alt="enter image description here"></p>