gowtham v gowtham v - 4 months ago 24
C# Question

Cannot find column

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;


here i want to update my name column, but i can't, but the student id is updated correctly, student name is not working.

Answer

You made a mistake here. Add quotes..

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