Solved

VB.NET Notepad

Posted on 2016-07-21
3
20 Views
Last Modified: 2016-07-21
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

0
Comment
Question by:Kevinfeening
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
Comment Utility
It is unclear what you mean by notepad. Is it Windows Notepad.exe you want to write to? Is it a notepad control within your application?
If it is the former you can create a temp text file, fill it with the table names from your SQL query and then open it with Notepad.exe using Process.Start
0
 

Author Comment

by:Kevinfeening
Comment Utility
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

0
 

Author Closing Comment

by:Kevinfeening
Comment Utility
Worked it out from the Process.start
used sendkeys.send with vbLF to fix
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now