Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 784905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:47:16+00:00 2026-05-14T20:47:16+00:00

I have a C# webservice on a Windows Server that I am interfacing with

  • 0

I have a C# webservice on a Windows Server that I am interfacing with on a linux server with PHP. The PHP grabs information from the database and then the page offers a “more information” button which then calls the webservice and passes in the name field of the record as a parameter. So i am using a WHERE statement in my query so I only pull the extra fields for that record. I am getting the error:

System.Data.SqlClient.SqlException:Invalid column name ’42’

Where 42 is the value from the name field from the database.

my query is

string selectStr = "SELECT name, castNotes, triviaNotes FROM tableName WHERE name =\"" + show + "\"";

I do not know if it is a problem with my query or something is wrong with the database, but here is the rest of my code for reference.

NOTE: this all works perfectly when I grab all of the records, but I only want to grab the record that I ask my webservice for.

public class ktvService  : System.Web.Services.WebService {

[WebMethod]
public string moreInfo(string show) {

    string connectionStr = "MyConnectionString";
    string selectStr = "SELECT name, castNotes, triviaNotes FROM tableName WHERE name =\"" + show + "\"";

    SqlConnection conn = new SqlConnection(connectionStr);
    SqlDataAdapter da = new SqlDataAdapter(selectStr, conn);
    DataSet ds = new DataSet();
    da.Fill(ds, "tableName");
    DataTable dt = ds.Tables["tableName"];

    DataRow theShow = dt.Rows[0];
    string response = "Name: " + theShow["name"].ToString() + "Cast: " + theShow["castNotes"].ToString() + " Trivia: " + theShow["triviaNotes"].ToString();

    return response;

} 

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:47:17+00:00Added an answer on May 14, 2026 at 8:47 pm

    Quick solution:

    I believe you need single quotes in your selectStr:

    string selectStr = 
    "SELECT name, castNotes, triviaNotes FROM tableName WHERE name = '" + show + "'";
    

    More information:

    In .NET, you’ll want to be sure you close out any connections explicitly when you no longer need them. The easiest way to do this is to wrap using statements around any types that implement IDisposable, such as SqlConnection in this case:

    using(SqlConnection conn = new SqlConnection(connectionStr))
    {
        SqlDataAdapter da = new SqlDataAdapter(selectStr, conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "tableName");
        DataTable dt = ds.Tables["tableName"];
    
        DataRow theShow = dt.Rows[0];
        string response = "Name: " + theShow["name"].ToString() + "Cast: " + theShow["castNotes"].ToString() + " Trivia: " + theShow["triviaNotes"].ToString();
    
        return response;
    }
    

    Additionally, it looks like your code could be easily subject to SQL injection. What if someone submits a form with the value: fake name' OR 1=1;DROP DATABASE someDbName;--?

    You’ll want to take advantage of SQL parameters, something like:

    SqlCommand cmd = new SqlCommand(
      "SELECT name, castNotes, triviaNotes FROM tableName WHERE name = @show", conn);
    
    cmd.Parameters.AddWithValue("@show", show);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webservice in java that receives a list of information to be
I have a asp.net webservice running in windows server 2003, i want it read/write
I am developing an Windows phone7 application, I have a .NET webservice that returns
I have a webservice that when called without specifying a callback will return a
I have a webservice that exists in an asp.net website. When I publish the
I have a webservice that is called by up to 10 clients. The webservice
I have a webservice that's behind form's authentication. The site that hosts the service
I have a windows service that is very heavily multithreaded (hundreds to thousands at
I have a windows service that is heavily multithreaded. Each thread calls various methods
i have a question, i have windows service which is deployed to the server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.