isha
isha

Reputation: 1

SQL Exception was unhandled-An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

SQL Exception was unhandled-An unhandled exception of type System.Data.SqlClient.SqlException occurred in System.Data.dll

 public DataSet getCustomers()
    {
        string Connectionstring = ConfigurationManager.ConnectionStrings["DbConn"].ToString();
        SqlConnection objConnection = new SqlConnection(Connectionstring);
        objConnection.Open();

        SqlCommand objCommand = new SqlCommand("Select * from Customer '"                                                  ,
                                              objConnection);
        DataSet objDataSet = new DataSet();
        SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
        objAdapter.Fill(objDataSet);

        objConnection.Close();
        return objDataSet;

    }

Upvotes: 0

Views: 222

Answers (3)

Enclosing your code in a Try Catch:

        public DataSet getCustomers()
    {
        try
        {
            string Connectionstring = ConfigurationManager.ConnectionStrings["DbConn"].ToString();
            SqlConnection objConnection = new SqlConnection(Connectionstring);
            objConnection.Open();

            SqlCommand objCommand = new SqlCommand("Select * from Customer '",
                                                  objConnection);
            DataSet objDataSet = new DataSet();
            SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
            objAdapter.Fill(objDataSet);

            objConnection.Close();
            return objDataSet;

        }
        catch (Exception ex)
        {
            Trace.Write(ex.Message);
            return null;
        }

    }

ex.Message will be: Unclosed quotation mark after the character string ''.

Just remove the ' after Customer

Upvotes: 0

Bungysheep
Bungysheep

Reputation: 40

Remove ' from query command:

SqlCommand objCommand = new SqlCommand("Select * from Customer" , objConnection);

Upvotes: 0

wazz
wazz

Reputation: 5078

Looks like an extra apostrophe after Customer ' ":

SqlCommand objCommand = new SqlCommand("Select * from Customer '", objConnection);

Upvotes: 2

Related Questions