TextBox String Value - SQL Query

Author Message
cjwallace

  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
  • Status: offline
TextBox String Value - SQL Query Monday, March 14, 2011 6:26 AM (permalink)
0
Guys.
I have created this Powershell form which has a textbox and OK button and some labels on it.
What i am trying to do is put lets say ABC into the text box and then when you hit OK it takes the value ABC and adds it to the SQL Query.

What i am a bit stuck on is where do i place the SQL code at the bottom in my script but also how do i create a string value based on the test entered in to the textbox?

Thanks for any help you can give. As you have guessed i am a noob at Powershell so really trying to find my feet
 
 #region ScriptForm Designer (Created with Admin Script Editor trial edition) #region Constructor [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") #endregion #region Post-Constructor Custom Code #endregion #region Form Creation
#Warning: It is recommended that changes inside this region be handled using the ScriptForm Designer.
#When working with the ScriptForm designer this region and any changes within may be overwritten.
#~~< iManage_Form >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$iManage_Form = New-Object System.Windows.Forms.Form
$iManage_Form.ClientSize = New-Object System.Drawing.Size(325, 131)
$iManage_Form.Text = "Check iManage & AD User Name"
#~~< Check_User_Name_TextBox >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Check_User_Name_TextBox = New-Object System.Windows.Forms.TextBox
$Check_User_Name_TextBox.Location = New-Object System.Drawing.Point(109, 22)
$Check_User_Name_TextBox.Size = New-Object System.Drawing.Size(100, 20)
$Check_User_Name_TextBox.TabIndex = 5
$Check_User_Name_TextBox.Text = ""
#~~< USA_iManage_Label >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$USA_iManage_Label = New-Object System.Windows.Forms.Label
$USA_iManage_Label.Location = New-Object System.Drawing.Point(224, 69)
$USA_iManage_Label.Size = New-Object System.Drawing.Size(100, 23)
$USA_iManage_Label.TabIndex = 4
$USA_iManage_Label.Text = "USA iManage"
#~~< EMEA_iManage_Label >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$EMEA_iManage_Label = New-Object System.Windows.Forms.Label
$EMEA_iManage_Label.Location = New-Object System.Drawing.Point(118, 69)
$EMEA_iManage_Label.Size = New-Object System.Drawing.Size(100, 23)
$EMEA_iManage_Label.TabIndex = 3
$EMEA_iManage_Label.Text = "EMEA iManage"
#~~< Active_Directory_Label >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Active_Directory_Label = New-Object System.Windows.Forms.Label
$Active_Directory_Label.Location = New-Object System.Drawing.Point(12, 69)
$Active_Directory_Label.Size = New-Object System.Drawing.Size(100, 23)
$Active_Directory_Label.TabIndex = 2
$Active_Directory_Label.Text = "Active Directory"
#~~< Check_User_Name_Label >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Check_User_Name_Label = New-Object System.Windows.Forms.Label
$Check_User_Name_Label.Location = New-Object System.Drawing.Point(12, 25)
$Check_User_Name_Label.Size = New-Object System.Drawing.Size(100, 23)
$Check_User_Name_Label.TabIndex = 1
$Check_User_Name_Label.Text = "Check User Name"
#~~< OK_Button >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$OK_Button = New-Object System.Windows.Forms.Button
$OK_Button.Location = New-Object System.Drawing.Point(215, 19)
$OK_Button.Size = New-Object System.Drawing.Size(43, 23)
$OK_Button.TabIndex = 0
$OK_Button.Text = "OK"
$OK_Button.UseVisualStyleBackColor = $true
$iManage_Form.Controls.Add($Check_User_Name_TextBox)
$iManage_Form.Controls.Add($USA_iManage_Label)
$iManage_Form.Controls.Add($EMEA_iManage_Label)
$iManage_Form.Controls.Add($Active_Directory_Label)
$iManage_Form.Controls.Add($Check_User_Name_Label)
$iManage_Form.Controls.Add($OK_Button) #endregion #region Custom Code #endregion #region Event Loop function Main{
 [System.Windows.Forms.Application]::EnableVisualStyles()
 [System.Windows.Forms.Application]::Run($iManage_Form)
} #endregion #endregion #region Event Handlers Main # This call must remain below all other event functions #endregion   $SQLServer = "SERVER NAME HERE" #use Server\Instance for named SQL instances!
$SQLDBName = "DATABASE NAME HERE"
$SqlQuery = "select * from " $SQLConn = New-Object System.Data.SqlClient.SqlConnection
$SQLConn.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True" $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SQLConn $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd $DS = New-Object System.Data.DataSet
$SqlAdapter.Fill($DS) $SQLConn.Close() clear $DS.Tables[0]   

 
#1
    cjwallace

    • Total Posts : 549
    • Scores: 0
    • Reward points : 0
    • Joined: 3/5/2005
    • Location: United Kingdom
    • Status: offline
    Re:TextBox String Value - SQL Query Sunday, March 20, 2011 4:26 AM (permalink)
    0
    Sorry guys.
     
    Can anyone help?
     
    #2
      dm_4ever

      • Total Posts : 3687
      • Scores: 82
      • Reward points : 0
      • Joined: 6/29/2006
      • Location: Orange County, California
      • Status: offline
      Re:TextBox String Value - SQL Query Tuesday, March 22, 2011 4:56 AM (permalink)
      0
      Your code would go under the event handler for the OK button you have which I don't believe you have.  I've used a tool like PrimalForms (free) that will let you build the form and easily add events similar to the way Visual Studio does.
      dm_4ever

      My philosophy: K.I.S.S - Keep It Simple Stupid
      Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
      Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9