title: Trying to insert a record into SQL Server with pyodbc and tkinter
body: <p>I am trying to write an application that will easily update a database when new equipment is added. So far I am able to connect to db and have created a GUI to show a few things.</p>
  
  <p>Now I am stuck at trying to insert a new record from an entry that a user makes. Basically a user enters 3 values: EquipmentName, HostName, and ValidationName that will create a new record in the database.</p>
  
  <p>I am getting an error: </p>
  
  <blockquote>
    <p>line 32, in submit<br>
    'ValidationName': ValidationName.get() pyodbc.ProgrammingError: ('The SQL contains 0 parameter markers, but 1 parameters were supplied', 'HY000')</p>
  </blockquote>
  
  <p>I have tried to google everything, but no luck in </p>
  
  <p>Sorry if this doesn't make sense, this is my first time trying to code with python.</p>
  
  <pre><code>from tkinter import *
  import pyodbc
  
  #Create application and size
  root = Tk()
  root.title('Application')
  root.geometry("400x400")
  
  # Connect to SQL Server database
  conn = pyodbc.connect('Driver={SQL Server};'
                    'Server=USGRE-PC0XLKJM\SQLEXPRESS;'
                    'Database=LAB;'
                    'Trusted_Connection=yes;')
  #Create cursor
  cursor = conn.cursor()
  cursor.execute('SELECT * FROM LAB.dbo.LabSystem')
  
  #Create submit function for database
  def submit():
  # Connect to SQL Server database
  conn = pyodbc.connect('Driver={SQL Server};'
                        'Server=USGRE-PC0XLKJM\SQLEXPRESS;'
                        'Database=LAB;'
                        'Trusted_Connection=yes;')
  # Create cursor
  cursor = conn.cursor()
  # Insert into table
  cursor.execute("INSERT INTO LAB.dbo.LabSystem VALUES (:EquipmentName, :HostName, :ValidationName)",
                 {
                     'EquipmentName': EquipmentName.get(),
                     'HostName': HostName.get(),
                     'ValidationName': ValidationName.get()
                 })
  # Commit changes
  conn.commit()
  
  # Close connection
  conn.close()
  
  # Clear the text boxes
  EquipmentName.delete(0, END)
  HostName.delete(0, END)
  ValidationName.delete(0, END)
  
  # Create query function
  def query():
  # Connect to SQl Server DB
  conn = pyodbc.connect('Driver={SQL Server};'
                        'Server=USGRE-PC0XLKJM\SQLEXPRESS;'
                        'Database=LAB;'
                        'Trusted_Connection=yes;')
  
  # Create cursor
  cursor = conn.cursor()
  # Query the database
  cursor.execute("SELECT *,SystemID FROM LAB.dbo.LabSystem")
  records = cursor.fetchall()
  #print(records)
  
  #Loop through results
  print_records = ''
  for record in records:
      print_records += str(record[0]) + " " +str(record[2]) + " " "\n"
  
  query_label = Label(root, text=print_records)
  query_label.grid(row=3, column=0, columnspan=2)
  
  # Commit changes
  conn.commit()
  
  # Close connection
  conn.close()
  
  # Create text boxes
  EquipmentName = Entry(root, width=30)
  EquipmentName.grid(row=0, column=1, padx=20)
  
  HostName = Entry(root, width=30)
  HostName.grid(row=1, column=1)
  
  ValidationName = Entry(root, width=30)
  ValidationName.grid(row=2, column=1)
  
  # Create labels for text boxes
  EquipmentName_label = Label(root, text="Equipment Name")
  EquipmentName_label.grid(row=0, column=0)
  
  HostName_label = Label(root, text="Host Name")
  HostName_label.grid(row=1, column=0)
  
  ValidationName_label = Label(root, text="Validation Name")
  ValidationName_label.grid(row=2, column=0)
  
  # Create submit button to add entries
  submit_btn = Button(root, text="Add record", command=submit)
  submit_btn.grid(row=6, column=0, columnspan=2, pady=10, padx=10)
  
  # Create a query button
  query_btn = Button(root, text="Show Records", command=query) 
  query_btn.grid(row=7, column=0, columnspan=2, pady=10, padx=10, ipadx=137)
  
  #Commit changes
  conn.commit()
  
  # Close connection
  conn.close()
  
  root.mainloop()
  </code></pre>