Question : How do i fix "Not a member of string" error in Vb.net code.

Hi Experts,

I get an "Not an member of string" error for the following line in this code:
MyString.Appenttext()

Can you explain how to fix this.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
Private Sub ExportDatasetToCsv(ByVal MyDataSet As DataSet)
        Dim dt As DataTable
        Dim dr As DataRow
        Dim MyString As String



        Dim bFirstRecord As Boolean = True
        Dim myWriter As New System.IO.StreamWriter("C:\MyTestCSV.csv")



        MyString = ""

        Try
            For Each dt In MyDataSet.Tables()
                For Each dr In dt.Rows
                    bFirstRecord = True

                    For Each field As Object In dr.ItemArray
                        If Not bFirstRecord Then
                            MyString.AppendText(",")

                        End If
                        MyString.AppendText(field.ToString)
                        bFirstRecord = False
                    Next

                    'New Line to differentiate next row              
                    MyString.AppendText(Environment.NewLine)

                Next

            Next

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

        'Write the String to the Csv File
        myWriter.WriteLine(MyString)

        'Clean up
        myWriter.Close()



    End Sub


Thanks
Stan

Answer : How do i fix "Not a member of string" error in Vb.net code.

You can write this:

    MyString.AppendText(",")

like this:

    MyString = MyString & ","

Similarly, change:

    MyString.AppendText(field.ToString)

To:

    MyString = MyString & field.ToString

And finally, this line:

    MyString.AppendText(Environment.NewLine)

Becomes:

    MyString = MyString & Environment.NewLine
Random Solutions  
 
programming4us programming4us