2016-08-06 3 views
0
case 3: 
int intAddOption; 
int intOption1; 
Console.WriteLine("Select You Want to Update single Data or Existing Student Record:\n"); 
Console.WriteLine("Select 11. for Update single Data "); 
Console.WriteLine("Select 12. For Update Existing Student Record\n"); 

intAddOption = Convert.ToInt32(Console.ReadLine()); 
if (intAddOption == 11) { 

    Console.WriteLine("select which details you want to update:"); 
    Console.WriteLine("select 1. update Id"); 
    Console.WriteLine("select 2. update Name"); 
    Console.WriteLine("select 3. update Contact"); 
    Console.WriteLine("select update option"); 
    intOption1 = Convert.ToInt32(Console.ReadLine()); 

    if (intOption1 == 1) { 

    Console.WriteLine("enter Student Id"); 
    string stringname3 = Console.ReadLine(); 
    DataRow[] rows = objdatatable.Select("[Student ID] =" + stringname3); 
    if (rows != null && rows.Length > 0) { 
    foreach(DataRow row in rows) { 
    Console.WriteLine("enter Id to update :"); 
    row["student Id"] = Console.ReadLine(); 
    } 
    Console.WriteLine("number of columns \n{0}", objdatatable.Columns.Count.ToString()); 
    Console.WriteLine("number of rows \n{0}", objdatatable.Rows.Count.ToString()); 
    Console.WriteLine("The Deatils Has been update"); 
    Console.WriteLine("The Total Number of Records \n{0}", objdatatable.Rows.Count.ToString()); 
    } 
    } else if (intOption1 == 2) { 
    Console.WriteLine("enter Student Name"); 
    string stringname4 = Console.ReadLine(); 
    DataRow[] rows = objdatatable.Select("[student Name] =" + stringname4); 
    if (rows != null && rows.Length > 1) { 
    foreach(DataRow row in rows) { 
    Console.WriteLine("enter Name to update :"); 
    row["student Name"] = Console.ReadLine(); 
    } 
    Console.WriteLine("number of columns \n{0}", objdatatable.Columns.Count.ToString()); 
    Console.WriteLine("number of rows \n{0}", objdatatable.Rows.Count.ToString()); 
    Console.WriteLine("The Deatils Has been update"); 
    Console.WriteLine("The Total Number of Records \n{0}", objdatatable.Rows.Count.ToString()); 

    } 

    } else if (intOption1 == 3) { 
    Console.WriteLine("enter Student Phone No"); 
    string stringname5 = Console.ReadLine(); 
    DataRow[] rows = objdatatable.Select("[Student Phone No] =" + stringname5); 
    if (rows != null && rows.Length > 0) { 
    foreach(DataRow row in rows) { 
    Console.WriteLine("enter Student Phone No to update :"); 
    row["student Phone No"] = Console.ReadLine(); 
    } 
    Console.WriteLine("number of columns \n{0}", objdatatable.Columns.Count.ToString()); 
    Console.WriteLine("number of rows \n{0}", objdatatable.Rows.Count.ToString()); 
    } 
    } 
} 
if (intAddOption == 12) { 
    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); 
    Console.WriteLine("Again you want to do operation select option:"); 
    Console.WriteLine("The Deatils Has been updated"); 
    Console.WriteLine("The Total Number of Records \n{0}", objdatatable.Rows.Count.ToString()); 
    } 
} 


break; 

여기 내 이름 열을 업데이트하고 싶지만 학생 ID가 올바르게 업데이트되어 학생 이름이 작동하지 않습니다.열을 찾을 수 없습니다

+0

Select() 메서드는 이름이 아닌 ID를 찾고 있으므로 null 행이 반환됩니다. 이름이나 ID로 학생들을 반환하는 objdatatable 메서드가 필요합니다. – jdweng

+0

else if (intOption1 == 2) { Console.WriteLine ("학생 이름 입력"); 문자열 stringname4 = Console.ReadLine(); DataRow [] rows = objdatatable.Select ("[학생 이름] ="+ 문자열 이름 4); if (rows! = null && rows.Length> 1) { foreach (행의 DataRow 행) {이것은 내 오류 지점입니다. –

+0

gowtham : 그렇지 않으면 Else가 필요하지 않습니다. 초보자를 혼동하지 마십시오. – jdweng

답변

0

여기 실수하셨습니다. 따옴표를 추가하십시오.

DataRow[] rows = objdatatable.Select("[student Name] ='" + stringname4 + "'"); 

은 기본적으로는 열 이름이 아닌 문자열로 stringname4을 고려 노력하고있다.

관련 문제