view raw
gowtham v gowtham v - 9 months ago 54
C# Question

it shows ==>Syntax error: Missing operand after 'Id' operator

namespace dt.cs
class Program
static void Main(string[] args)
DataTable objdatatable;
DataRow objdatarow;
DataRow[] objdatarowcollection;
int intcount,intcount1;
objdatatable = new DataTable("Student Details");
objdatatable.Columns.Add("Student ID", typeof(string));
objdatatable.Columns.Add("Student Name", typeof(string));
objdatatable.Columns.Add("Phone No", typeof(string));

for (intcount = 1; intcount <= 5; intcount++)
Console.WriteLine("enter your choice:\n 1.Add Record \n 2.Delete Record \n 3.Update Record\n 4.table rename\n 5.View Record \n 6.exit");

intcount = Convert.ToInt32(Console.ReadLine());

switch (intcount)
case 1:
Console.WriteLine("\nHow Many Record You Want To Add:");
intcount1 = Convert.ToInt32(Console.ReadLine());
for (intcount = 1; intcount <= intcount1; intcount++)
objdatarow = objdatatable.NewRow();
Console.WriteLine("\nEnter Student Id:\n");
objdatarow["student Id"] = Console.ReadLine();
Console.WriteLine("\nEnter Student Name:\n");
objdatarow["student Name"] = Console.ReadLine();
Console.WriteLine("\nEnter student Contact Number:\n");
objdatarow["phone no"] = Console.ReadLine();


case 2:

Console.WriteLine("Select Id for Delete Record");
string stringname = Console.ReadLine();
objdatarowcollection = objdatatable.Select("student Id ='" + stringname + "'");
if(objdatarowcollection!=null && objdatarowcollection.Length > 0)
Console.WriteLine("The Number of Records \n{0}", objdatatable.Rows.Count.ToString());

This is my code, here i cant to delete particular record, what i was make mistake?

please find out my mistake friends
thanks in advance


You need to decorate your column name with [Table Name] since it is composed of multiple words:

objdatarowcollection = objdatatable.Select("[Student ID] =" + stringname);

Side Note: This is not a syntax error, but a run-time error caused by incorrect expression syntax.