Меню

Too many characters in character literal ошибка

Sashaa_i

0 / 0 / 1

Регистрация: 02.11.2014

Сообщений: 64

1

27.12.2015, 12:11. Показов 23232. Ответов 3

Метки нет (Все метки)


return ‘pervy method’; — в этой строке выдает ошибку CS1012 Too many characters in character literal. Помогите пожалуйста разобраться что к чему и как исправить.

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Zadtri
{
class Program
{
delegate string DelegateOne();
static void Main(string[] args)
{
    DelegateOne DL = delegate ()
 
    {
        return 'pervy method';
        };
    
    Console.WriteLine(DL());
    Console.ReadKey();
}
}
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Администратор

Эксперт .NET

15226 / 12265 / 4902

Регистрация: 17.03.2014

Сообщений: 24,867

Записей в блоге: 1

27.12.2015, 13:40

2

Лучший ответ Сообщение было отмечено Sashaa_i как решение

Решение

Sashaa_i, строки в C# должны быть в двойных кавычках. Одинарные кавычки используются для символов.



1



0 / 0 / 1

Регистрация: 02.11.2014

Сообщений: 64

27.12.2015, 13:58

 [ТС]

3

всё равно ошибки

Миниатюры

Ошибка CS1012 Too many characters in character literal.
 



0



0 / 0 / 1

Регистрация: 02.11.2014

Сообщений: 64

27.12.2015, 14:04

 [ТС]

4

а нет, все хорошо, получилось, спасибо)



0



  • Remove From My Forums
  • Question

  • User514441003 posted
    //I need to write Number of days in month of Year method . However, the error CS1012: Too many characters in character literal. I think error in ch==’10’ and ch==’12’ . But how to solve it . Besides this , what is «ildasm» how to use it? thx ——————————————————————————————
    using System; public class Hello { static void Main(string[] args) { int ch=Console.Read(); int state=0; switch (state) { case 0: if (ch ==’1′ || ch==’3′ || ch==’5′ || ch==’7′ || ch==’8′ || ch==’10’ || ch==’12’) { Console.WriteLine(«31»); } else if (ch ==
    ‘2’) goto case 2; else goto default; case 1: if (ch ==’4′ || ch==’6′ || ch==’9′ || ch==’11’) { Console.WriteLine(«30»); } else goto default; case 2: Console.WriteLine(«28 || 29!»); break; default: Console.WriteLine(«illegal character: » + (char) ch); break;
    } } }

Hi all,
I’m having problem when deploying my web application.
My application runs fine in website application, but when i convert to web application project, its showing some errors when i compile.

The error shows as — Too many characters in character literal in sql query,

where i m using dataset in my application to filter search in my developer express report.So,the error is from .xsd file,from sql query :

example:

<CommandText>
SELECT TOP (100) PERCENT CSGNDTL.ItemCode AS MBBTag, 
       CAST(GRDTL.SerialNoList AS nvarchar(30)) AS SerialNumber, 
       GRDTL.UDF_FANumber AS FANumber, GRDTL.UDF_CSCManagedNumber AS CSCManagedCode, 
       Item.Description AS ModelNo, Item.Desc2 AS ModelName, 
       ItemType.Description AS Classification, 
       Location.Location + ' - ' + Location.Description AS Location, 
       CSGN.CreatedUserID AS ApproveBy, CSGN.CreatedTimeStamp AS ApproveDate,
       Item.UDF_OwnerShip
FROM CSGN 
INNER JOIN CSGNDTL ON CSGN.DocKey = CSGNDTL.DocKey 
INNER JOIN GRDTL ON CSGNDTL.ItemCode = GRDTL.ItemCode 
INNER JOIN Debtor ON CSGN.DebtorName = Debtor.CompanyName 
INNER JOIN Item ON CSGNDTL.ItemCode = Item.ItemCode 
INNER JOIN Location ON CSGNDTL.Location = Location.Location 
INNER JOIN ItemType ON Item.UDF_Classification = ItemType.ItemType 
INNER JOIN SerialNoTrans ON CSGNDTL.DtlKey = SerialNoTrans.DtlKey 
WHERE (CSGN.Description = 'ACTIVE') AND (Location.Location LIKE @Location) 
ORDER BY ApproveDate DESC
</CommandText>

the error shows at wherever i use the ‘ — ‘ and ‘ACTIVE’

anyone knows what causing this error?


1 solution

Solution 1

Normally, single quotes i.e.

' '

are used for specifying character literal that is of 2 bytes ==> only one character.
Whereas when we want to use string or a number of characters, we use double quotes i.e.

" "

.
Thats where the problem is. Just try changing single quotes to double and you’ll be there!
Good Luck!

Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

 

Print

Answers RSS

Top Experts
Last 24hrs This month

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

  • Remove From My Forums
  • Вопрос

  • Hello,

    I am trying to insert some values retrieved from textboxes into an Access DB using ASP.NET. When I try to run this code I get an error reading «Too many characters in character literal». What does this mean? Also, how do I break new lines, does way this look ok?

    string connectionString = ConfigurationManager.ConnectionStrings[«ConnectionString1»].ConnectionString;

    string sQuery2 = INSERT INTO Member(FirstName, LastName, StreetAdress, PostalAdress, Telephone, Email),

    VALUES (‘strFirstName’, ‘strLastName’, ‘strStreetAddress’, ‘strPostalAddress’, ‘strTelephone’, ‘strEmail’);

    OleDbConnection oOleDbConnection = new OleDbConnection(connectionString);

    oOleDbConnection.Open();

    OleDbCommand command2 = new OleDbCommand(sQuery2, oOleDbConnection);

    OleDbDataReader reader2 = command2.ExecuteNonQuery();

Ответы

  • In SQL Server 2005 and up you need to first UNPIVOT the table and then use the MIN function. So, it’s pretty much as you were doing or using UNPIVOT syntax instead of UNION ALL.

    In other words:

    declare @T table (AreaCode int identity(1,1), 
    Distance_Area1 int, Distance_Area2 int,Distance_Area3 int,
    Distance_Area4 int,Distance_Area5 int,Distance_Area6 int) 
    insert into @T values (1,2,3,4,5,6), (7,15,8,10,11,12)
    
    SELECT AreaCode, min(Distance) as MinDistance
    FROM (select * from @t) p
    UNPIVOT
     (Distance FOR AreaName IN 
      (Distance_Area1, Distance_Area2,Distance_Area3,
    Distance_Area4,Distance_Area5,Distance_Area6)
    ) AS unpvt group by AreaCode

    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog

    • Помечено в качестве ответа

      8 ноября 2010 г. 1:15

  • I assume that «strFirstName», «strLastName» etc are variables that you have declared in  your application. I guess you need to change your query as follows:string sQuery2 = String.Format(«INSERT INTO Member(FirstName, LastName, StreetAdress, PostalAdress, Telephone, Email) VALUES (‘{0}’,'{1}’,'{2}’,'{3}’,'{4}’,'{5}’)», strFirstName,strLastName,strStreetAddress,strPostalAddress,strTelephone,strEmail);

    The above statement will stuff the values of the variables into the insert query. Another option is to use a parameterized query. You might get better help if you post it in the MS ACCESS forums.

    • Помечено в качестве ответа
      Kalman Toth
      8 ноября 2010 г. 1:15

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Too hot ошибка вейп
  • Too few arguments ошибка