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 8094679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:52:18+00:00 2026-06-05T20:52:18+00:00

hello i build a webservice in visual studio 2010. i get some id’s which

  • 0

hello i build a webservice in visual studio 2010. i get some id’s which are saved in a string looks like this:

string room_ids="5,11,99,42";

they are separated by comma. i created a foreach loop to split the ids and from the comma and use them in my sql query until the ids are finished. but it doesn’t work. i get an error it says:

Error converting data type nvarchar to numeric

here is my code, thanks in advance for your help!

internal static List<RAUM> Raum(string RAUMKLASSE_ID, string STADT_ID, string GEBAEUDE_ID, string REGION_ID)
{       
    List<RAUM> strasseObject = new List<RAUM>();
    string[] allegebaude = GEBAEUDE_ID.Split(new char[] { ',' });

    foreach (string gebaudeid in allegebaude)
    {
        Trace.WriteLine("SIND JETZT DRINNE");
        Trace.WriteLine(gebaudeid);

        using (SqlConnection con = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=BOOK-IT-V2;Integrated Security=true;"))
        using (SqlCommand cmd = new SqlCommand(@"SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID FROM RAUM r WHERE RAUMKLASSE_ID = ISNULL(@Raumklasse_ID, RAUMKLASSE_ID) AND STADT_ID = ISNULL(@Stadt_ID, STADT_ID) AND GEBAEUDE_ID = ISNULL(@gebaudeid,GEBAEUDE_ID ) AND REGION_ID = ISNULL(@Region_ID, REGION_ID)", con))
        {
            con.Open();
            if (!StringExtensions.IsNullOrWhiteSpace(RAUMKLASSE_ID))
                cmd.Parameters.AddWithValue("@Raumklasse_ID", RAUMKLASSE_ID);
            else
                cmd.Parameters.AddWithValue("@Raumklasse_ID", DBNull.Value);

            if (!StringExtensions.IsNullOrWhiteSpace(STADT_ID))
                cmd.Parameters.AddWithValue("@Stadt_ID", STADT_ID);
            else
                cmd.Parameters.AddWithValue("@Stadt_ID", DBNull.Value);

            if (!StringExtensions.IsNullOrWhiteSpace(GEBAEUDE_ID))
                cmd.Parameters.AddWithValue("@gebaudeid", GEBAEUDE_ID);
            else
                cmd.Parameters.AddWithValue("@gebaudeid", DBNull.Value);

            if (!StringExtensions.IsNullOrWhiteSpace(REGION_ID))
                cmd.Parameters.AddWithValue("@Region_ID", REGION_ID);
            else
                cmd.Parameters.AddWithValue("@Region_ID", DBNull.Value);



            using (SqlDataReader rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    if (rdr["BEZEICHNUNG"] != DBNull.Value && rdr["ID"] != DBNull.Value)
                    {
                        strasseObject.Add(new RAUM()
                        {
                            RaumName = rdr["BEZEICHNUNG"].ToString(),
                            RaumID = rdr["ID"].ToString()

                        });
                    }
                }
            }

        }
    }
    return strasseObject;
}
  • 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-06-05T20:52:20+00:00Added an answer on June 5, 2026 at 8:52 pm

    If you already have the IDs in a comma-separated string (called IDstring) then you can just do something like this:

    sqlQuery = "SELECT Columns FROM table WHERE ID IN (" + IDstring + ")";
    

    In your specific case, don’t split the original string (GEBAEUDE_ID) but use it as it is:

       // Don't use a foreach loop any more
       string gebaudeIdSection = " AND GEBAEUDE_ID IN (" + GEBAEUDE_ID + ") ";
       if (string.IsNullOrEmpty(GEBAUDE_ID)) { gebaudeIdSection = ""; } // if there are no ids, let's remove that part of the query completely.
       using (SqlConnection con = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=BOOK-IT-V2;Integrated Security=true;"))
       using (SqlCommand cmd = new SqlCommand(@"SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID FROM RAUM r WHERE RAUMKLASSE_ID = ISNULL(@Raumklasse_ID, RAUMKLASSE_ID) AND STADT_ID = ISNULL(@Stadt_ID, STADT_ID)" + gebaudeIdSection + " AND REGION_ID = ISNULL(@Region_ID, REGION_ID)", con))
       { // The rest of the code is the same as before...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I'd like to build a Rails Brick using a Sheevaplug from Marvell (O.S.
This is my first Class Hello.java public class Hello { String name = ;
Hello I know all about http://www.php.net/manual/en/function.http-build-query.php to do this however I have a little
We have file name like hello-world-part-2.html Help me please to build pattern to extract
I'm trying to build a hello world using GTK, which includes the line: #include
hello i wanted to build I get $date and $date1 from form xxx. I
Hello everyone I have error which breaks up my build for no reason, here
This simple program below does not build for some reason. It says undefined reference
hello i build a webservice to communicate with the iPhone. i want to display
Hello i build a small app using Android, in this app i built two

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.