Dim writer As StreamWriter = File.CreateText("D:\ IMS.csv")For i As Integer = 1 To ds.Tables(0).Columns.Count - 1writer.Write(ds.Tables(0).Columns(i))If i < ds.Tables(0).Columns.Count - 1 Thenwriter.Write(",")End IfNextwriter.Write(writer.NewLine)For Each dr As DataRow In ds.Tables(0).RowsFor i As Integer = 0 To ds.Tables(0).Columns.Count - 1If Not Convert.IsDBNull(dr(i)) Thenwriter.Write(dr(i).ToString())End IfIf i < ds.Tables(0).Columns.Count - 1 Thenwriter.Write(",")End IfNextwriter.Write(writer.NewLine)Next