Link to home
Start Free TrialLog in
Avatar of K Feening
K FeeningFlag for Australia

asked on

VB.NET Notepad

HI Experts

I have an SQL that writes to a ComboBox can you explain how to write it to the combobox and open notepad and write to it so customer doesn't need to cut and paste from combo to notepad

Dim Sql As String = String.Format("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.tables ORDER BY TABLE_NAME")
            Dim reader As Data.IDataReader = DataConnector.GetReader(Sql, Nothing)
            Do While reader.Read = True
                mTablesComboBox.Items.Add(reader.GetString(0))
            Loop

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of K Feening

ASKER

Sorry its Windows notepad

the SendMessage(notepad.MainWindowHandle, WM_SETTEXT, IntPtr.Zero, texttoadd) sends nothing
I tried SendKeys.SendWait(texrttosend) sends some info not all and sometimes exits the program
there may be up to 50 fields in the table I want them on separate lines how do you  populate the notepad or is the only way is to create a text file and open it. I would rather send direct but if a temp file is the only way how do you open It in the notpad with out using file open

Const WM_SETTEXT As Integer = &HC
        <DllImport("user32.dll")> _
        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, <MarshalAs(UnmanagedType.LPStr)> ByVal lParam As String) As IntPtr
        End Function

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim npad As ProcessStartInfo = New ProcessStartInfo("NotePad.exe")
            npad.UseShellExecute = True

            Dim notepad As Process = Process.Start(npad)
            Dim texttoadd As String = ""

            Dim sql As String = "Select column_name from information_schema.columns where table_name = @TableName order by column_name"
            Dim params As New DataParameterCollection("@TableName", "Employee")
            Using dataConnector As IDataConnector = DataUtils.GetDataConnector()
                Dim reader As Data.IDataReader = dataConnector.GetReader(sql, params)
                Do While reader.Read = True
                    texttoadd = vbLf & reader.GetString(0)
                    SendMessage(notepad.MainWindowHandle, WM_SETTEXT, IntPtr.Zero, texttoadd)
                Loop
                reader.Close()
            End Using
        End Sub
    End Class

Open in new window

Worked it out from the Process.start
used sendkeys.send with vbLF to fix