this code works well but somehow it is giving me a warning saying: "Variable 'str1' is used before it has been assigned a value. A null reference exception could result at runtime."How can i remove the warning.

Public Shared Function getAllColumnNames(ByVal tblname As String) As String()
        Dim com As New OleDbCommand
        Dim con As OleDbConnection
        Dim str1() As String
        Dim dtable1 As DataTable
        con = New OleDb.OleDbConnection("Provider=SQLOLEDB;server=...;uid=..;pwd=..;database=..")
        con.Open()
        com.Connection = con
        dtable1 = con.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Columns, New Object() {Nothing, Nothing, tblname, Nothing})
        For i = 0 To dtable1.Rows.Count - 1
            ReDim Preserve str1(i)
            str1(i) = dtable1.Rows(i).Item(3).ToString
        Next i
        Return str1
    End Function

Hi,

You could try:

Dim str1() As String = Nothing
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.