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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:23:28+00:00 2026-06-06T22:23:28+00:00

i’d like to know why this class doesn’t work, but if this piece of

  • 0

i’d like to know why this class doesn’t work, but if this piece of code is written in the aspx page directly, it works.
I want this in a class because is called several times in several pages to check if the user is already counted as visitor.
The principal idea of this is to count the number of users that are seeing my website.


The error is this:
Incorrect syntax near ‘:’

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near ‘:’.


THIS IS THE CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Data;
using System.Text;

namespace Project
{
    public class ipAddress
    {
        SQL com = new SQL(); //Class to make SQL connection and do querys
        public void GetPublicIP()
        {
            WebClient web = new WebClient();
            System.IO.Stream stream = web.OpenRead(url);
            string text = "";
            using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
            {
                text = reader.ReadToEnd();
                reader.Close();
            }
            string results = "";
            try
            {
                foreach (DataRow item in com.Execute("select * from table where ip = '" + text + "' and data = '" + DateTime.Now.ToShortDateString() + "';").Rows)
                {
                    results = item["ip"].ToString();
                }
                if (results == "")
                {
                    com.FazerComando("insert into table (ip, date) values ('" + text + "', '" + DateTime.Now.ToShortDateString() + "');");
                }
            }
            catch { }
        }
    }
 }

Regards…

  • 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-06T22:23:29+00:00Added an answer on June 6, 2026 at 10:23 pm

    Well we don’t know what this SQL class is, but it looks like you’re injecting values directly into SQL, which is a very bad idea. It invites SQL injection attacks, mixes code and data, and makes conversions around numbers and date/time values much harder than they need to be. (In this particular case, you’re lucky – the string you’re building is just invalid SQL. It’s not, say, wiping out your database.)

    Instead, you should be using parameterized SQL where you include “placeholders” in the SQL itself, and provide the values separately.

    Assuming SQL is your own class, you should give it the facility to use parameterized SQL. See SqlCommand.Parameters for an example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
I want to count how many characters a certain string has in PHP, but

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.