2016-08-06 95 views
-1
namespace dt.cs 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      DataTable objdatatable; 
      DataRow objdatarow; 
      DataRow[] objdatarowcollection; 
      int intcount,intcount1; 
      try 
      { 
       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(); 
           objdatatable.Rows.Add(objdatarow); 
          } 

          break; 

         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) 
           objdatarowcollection[0].Delete(); 
           Console.WriteLine("The Number of Records \n{0}", objdatatable.Rows.Count.ToString()); 
           break; 

これは私のコードです、ここでは特定のレコードを削除できません。これではありません:==>構文エラー: 'Id'演算子の後にオペランドがありません

objdatarowcollection = objdatatable.Select("[student Id] ='" + stringname + "'"); 

側注:

私のミスの友人 あなたはそれが複数の単語で構成されているので、[Table Name]を使用して列名を飾るために必要

+0

これは私のエラーラインだと思うobjdatarowcollection = objdatatable.Select( "student Id = '" + stringname + "'"); –

+0

[再度同じ質問をしました](http://stackoverflow.com/questions/38801385/i-got-missing-operand-after-id-operator-error-what-happen-in-my-code-frien )。答えに正しいものがなかったのは何ですか?ところで、ここで受け入れられた答えは、文字列値 – Steve

答えて

0

事前のおかげを見つけてください構文エラーですが、誤った式構文によって実行時エラーが発生します。

+0

の引用符が足りなくなっているので動作しません。現在は動作しています –

+0

_it's working_?文字列の値を引用符で囲むことはほとんどありません。 – Steve

+0

@Steveはいそれは動作します。 – user3185569