Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.NET Notepad

Posted on 2016-07-21
3
Medium Priority
?
58 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 25

Accepted Solution

by:
chaau earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

885 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