none
Unhandled Exception RRS feed

  • Question

  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace _11._12._2019
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btnOK_Click(object sender, EventArgs e)
            {
                using(SqlConnection cn=new SqlConnection(Properties.Settings.Default.connString))
                {
    
                    var selectStatement = "select FirstName, LastName from hawk.dbo.Customers" +
                        "where Identifier=@ID";
    
                    using(var cmd=new SqlCommand() { CommandText=selectStatement, Connection=cn})
                    {
                        
                        cmd.Parameters.AddWithValue("@ID", 100);
                        cn.Open();
                            cmd.ExecuteReader();
    
                      
    
    
    
    
    
    
    
    
                    }
    
    
    
    
                }
            }
        }
    }
    

    An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
    Incorrect syntax near '='.
    Thursday, December 12, 2019 1:33 PM

Answers

  • Perhaps adding a space between hawk.dbo.Customers and where

    var selectStatement = "select FirstName, LastName from hawk.dbo.Customers where Identifier=@ID";

    And is haek the catalog? You can set the default catalog in the connection string.

    Example

    Private ConnectionString As String = "Data Source=.\\SQLEXPRESS;Initial Catalog=hawk;Integrated Security=True"


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Thursday, December 12, 2019 2:38 PM
    Moderator
  • var selectStatement = "select FirstName, LastName from hawk.dbo.Customers" +

                        "where Identifier=@ID";

    I think you should place a 'space' after hawk.dbo.Customers or before the 'where' to get seperation

    select * from blah where blah

    Otherwise it's this.

    select * from blahwhere blah

    • Marked as answer by Decompressor Thursday, December 12, 2019 3:03 PM
    Thursday, December 12, 2019 2:47 PM

All replies

  • Perhaps adding a space between hawk.dbo.Customers and where

    var selectStatement = "select FirstName, LastName from hawk.dbo.Customers where Identifier=@ID";

    And is haek the catalog? You can set the default catalog in the connection string.

    Example

    Private ConnectionString As String = "Data Source=.\\SQLEXPRESS;Initial Catalog=hawk;Integrated Security=True"


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Thursday, December 12, 2019 2:38 PM
    Moderator
  • var selectStatement = "select FirstName, LastName from hawk.dbo.Customers" +

                        "where Identifier=@ID";

    I think you should place a 'space' after hawk.dbo.Customers or before the 'where' to get seperation

    select * from blah where blah

    Otherwise it's this.

    select * from blahwhere blah

    • Marked as answer by Decompressor Thursday, December 12, 2019 3:03 PM
    Thursday, December 12, 2019 2:47 PM
  • Thank you!
    Thursday, December 12, 2019 3:04 PM