Solved

VB.NET Notepad

Posted on 2016-07-21
3
32 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
ID: 41723979
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
ID: 41724007
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
ID: 41724031
Worked it out from the Process.start
used sendkeys.send with vbLF to fix
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 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