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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:40:33+00:00 2026-05-24T11:40:33+00:00

I currently have the following code: <%@ WebService Language=C# Class=Notifications %> using System; using

  • 0

I currently have the following code:

<%@ WebService Language="C#" Class="Notifications" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Script;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

public class Notification
{
    public int id;
    public string text;

    public Notification(int m_id, string m_text)
    {
        id = m_id;
        text = m_text;
    }

    public Notification() {}
}

[System.Web.Script.Services.ScriptService]
public class Notifications : System.Web.Services.WebService {
    List<Notification> Notification = new List<Notification>();

    [WebMethod()]
    public List<Notification> GetNotifications()
    {
        var notifications = new List<Notification>();

        using (SqlConnection objSQLConnection = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connString"]))
        {
            using (SqlCommand objSQLCommand = new SqlCommand("select * from table1 where col1 = @user", objSQLConnection))
            {
                objSQLCommand.Parameters.Add("@user", SqlDbType.VarChar, 5).Value = "abc";

                objSQLConnection.Open();
                using (SqlDataReader objSQLDataReader = objSQLCommand.ExecuteReader())
                {

                    while (objSQLDataReader.Read())
                    {
                        notifications.Add(new Notification(objSQLDataReader["id"], objSQLDataReader["text"]));
                    }

                }
            }
        }

        return notifications;
    }

}

Which is giving me the following error:

Compiler Error Message: CS1502: The best overloaded method match for 'Notification.Notification(int, string)' has some invalid arguments

On the line:

notifications.Add(new Notification(objSQLDataReader["id"], objSQLDataReader["text"]));

Anyone know why this is happening?

  • 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-24T11:40:34+00:00Added an answer on May 24, 2026 at 11:40 am

    There seems to be some missing from the function, you never create the Notifications object for example. If you use implicitly created variables in VB, that will most likely not work to convert into C# (and is not encouraged in VB either). Also, I would encourage you to use Using blocks to make sure that everything is closed and disposed properly:

    <WebMethod()> _
    Public Function GetNotifications() As List(Of Notification)
      Dim notifications As New List(Of Notification)()
    
      Using connection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString"))
        Using command = New SqlCommand("select * from table1 where col1 = @user", connection)
          command.Parameters.Add("@user", SqlDbType.VarChar, 5).Value = sUser;
    
          connection.Open()
          Using reader = command.ExecuteReader()
    
            Dim idIndex As Integer = reader.GetOrdinal("id")
            Dim textIndex As Integer = reader.GetOrdinal("text")
    
            While reader.Read()
              notifications.Add(New Notification(reader.GetInt32(idIndex), reader.GetString(textIndex)))
            End While
    
          End Using
        End Using
      End Using
    
      Return notifications
    End Function
    

    Now it should (ideally) convert into:

    [WebMethod()]
    public List<Notification> GetNotifications() {
      var notifications = new List<Notification>();
    
      using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connString"])) {
        using (SqlCommand command = new SqlCommand("select * from table1 where col1 = @user", connection)) {
          command.Parameters.Add("@user", SqlDbType.VarChar, 5).Value = sUser;
    
          connection.Open();
          using (SqlDataReader reader = command.ExecuteReader()) {
    
            int idIndex = reader.GetOrdinal("id")
            int textIndex = reader.GetOrdinal("text")
    
            while (reader.Read()) {
              notifications.Add(new Notification(reader.GetInt32(idIndex), reader.GetString(textIndex)));
            }
    
          }
        }
      }
    
      return notifications;
    }
    

    Edit:

    Changes done:

    • Changed to brackets when accessing AppSettings
    • Changed to brackets when accessinfg objSQLDataReader
    • Changed reader code to use GetOrdinal, GetInt32 and GetString
    • Changed variable names; removed hungarian notation
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following code: <form action=process.php method=POST> <fieldset class=form-search> <input type=text class=input-text
currently I have the following code: String select = qry.substring(select .length(),qry2.indexOf( from )); String[]
currently i have jdbc code with the following basic stucture: get Connection (do the
I have a select query that currently produces the following results: Description Code Price
I have the following problem using subversion: I'm currently working on the trunk of
currently I have following code: home.php <form name='myformname' id='myformid'> <input type='text' name='mytext1' value='abc'> <input
I currently have the following code : $content = <name>Manufacturer</name><value>John Deere</value><name>Year</name><value>2001</value><name>Location</name><value>NSW</value><name>Hours</name><value>6320</value>; I need to
I currently have the following code: events.detect do |event| #detect does the block until
I have the following code, which connects to a web service and returns an
I have the following web service that allows me uploading files: [WebService(Namespace = http://tempuri.org/)]

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.