Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Every Body,

I am designing a desktop application (Windows) using VB.NET 2008, SQL Server 2005.

I have one FORM with a DataGridView. I have added a some column in grid view as follows:

grdDesID, grdDesName, grdDesShortName, grdDesDescription, grdIsDefault in design view.

********************************************************************
I have a following code:

VB.NET
Private Sub EmpDesignation_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Declaration
        Dim OConn As OleDbConnection
        Dim strSQL As String
        Dim SQLCmd As OleDbCommand
        Dim OReader As OleDbDataReader
        Dim strConn As String = ("Provider = SQLOLEDB;Data Source = INDABS\RMS;Initial Catalog = INDB;User ID = sa;Password = s@1234;Persist Security Info = TRUE;")
        OConn = New OleDbConnection(strConn)
        strSQL = "SELECT DesID,DesName,DesShortName,DesDescription,DesIsDefault FROM dbo.hrEmpDesignation"
        Try
            OConn.Open()
            Dim i As Integer
            i = 0
            SQLCmd = New OleDbCommand(strSQL, OConn)
            OReader = SQLCmd.ExecuteReader
            Do While OReader.Read()
                grvDesignationList.RowCount = grvDesignationList.RowCount + 1
                i = i + 1
            Loop
            OReader.Close()
            i = 0
            SQLCmd = New OleDbCommand(strSQL, OConn)
            OReader = SQLCmd.ExecuteReader
            Do While OReader.Read()
                grvDesignationList.Item(0, i).Value = OReader("DesID")
                grvDesignationList.Item(1, i).Value = OReader("DesName")
                grvDesignationList.Item(2, i).Value = OReader("DesShortName")
                grvDesignationList.Item(3, i).Value = OReader("DesDescription")
                grvDesignationList.Item(4, i).Value = OReader("DesIsDefault")
                i = i + 1
            Loop
        Catch ex As Exception
            MessageBox.Show(ex.Message, "OlEDB Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

*******************************************************************

Though data can be load in data grid but still i receive this message " index was out of range. must be non-negative and less than the size of the collection. Parameter name: Index" when i run the APPLICATION.

PLEASE HELP !!!!!!!!!!!

rigtsale :confused:
Posted
Updated 16-Apr-10 3:15am
v2

I assume there's an amusing reason why you didn't tell us what line gives the error, assure us that you've read the ( plain English ) message, and explained why, using your debugger, you feel sure the message is in error, the compiler is wrong, and you're using indices that are valid ?


rigtsale wrote:
Dim strConn As String = ("Provider = SQLOLEDB;Data Source = INDABS\RMS;Initial Catalog = INDB;User ID = sa;Password = s@1234;Persist Security Info = TRUE;")


There's at least three reasons I'd fire someone who wrote this code. I assume you're just learning, but learn more about DB security and writing enterprise level apps, please.


rigtsale wrote:
grvDesignationList.Item(0, i).Value = OReader("DesID")
grvDesignationList.Item(1, i).Value = OReader("DesName")
grvDesignationList.Item(2, i).Value = OReader("DesShortName")
grvDesignationList.Item(3, i).Value = OReader("DesDescription")
grvDesignationList.Item(4, i).Value = OReader("DesIsDefault")


I take it this is your problem. Why are you not just using databinding ?
 
Share this answer
 
Hi Christian Graus,

Thanks for the advice man. So can you please tell me how should i bind the data according to the case which i have mentioned.

I would really appreciate if you can take me out of this stage.

Thanks,

rigtsale
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900