MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

ADO.NET

ADO.NET Projects

ADO.NET Project 1

ADO.NET Examples

Examples

Displaying the Row States in C#
Previous Home Next
private static void DisplayROWs(string , DataTable table)
{
Console.Clear();
Console.WriteLine("\n");
Console.WriteLine(s);
Console.WriteLine("-------------------------------------------");
foreach (DataRow dr in table.Rows)
{
Console.WriteLine(dr.RowState.ToString());
}
Console.WriteLine("\nPress Enter to Continue ..") ;
Console.Read() ;
}

Filling a DataTable and Displaying the Row States in C#

static void Main(string[] args)
{
using (SqlConnection scon = new SqlConnection(connectionString))
{
SqlCommand scmd = scon.CreateCommand();
scmd.CommandText = "Select * from student";
SqlDataAdapter sqlDa = new SqlDataAdapter(scmd);
DataTable StudentTable = new DataTable("student");
sqlDa.Fill(StudentTable);
DisplayRowStates(
"Row states for a freshly filled DataTable:",StudentTable);
}
}

 

Making Changes to the DataTable in C#

DataRow dr;
// Make Changes - Modify the puppy
dr = StudentTable.Rows[0];
dr["StudentName"] = "Anil";
// Make Changes - Delete the cat
dr = StudentTable.Rows[1];dr.Delete();
// Leave the Horse untouched.
// Make Changes - Insert a Record
dr = StudentTable.NewRow();
dr["StudentID"] = 4;dr["StudentName"] = "Ajay";
StudentTable.Rows.Add(dr);
DisplayRowStates("Row states for a modified DataTable:", StudentTable);

Setting Various Commands in C#

// Update the changes back to the database.
SqlCommandBuilder sqlcommr 
   = new SqlCommandBuilder(sqlDa);
// Setup Update Command
sqlDa.UpdateCommand = sqlcommr.GetUpdateCommand();
Console.WriteLine("Update Command: " 
   + sqlDa.UpdateCommand.CommandText);
// Setup Insert Command
sqlDa.InsertCommand = sqlcommr.GetInsertCommand();
Console.WriteLine("Insert Command: " 
   + sqlDa.InsertCommand.CommandText);
// Setup Delete Command
sqlDa.DeleteCommand = sqlcommr.GetDeleteCommand() ;
Console.WriteLine("Delete Command: " 
   + sqlDa.DeleteCommand.CommandText);
sqlDa.Update(animalsTable);
Previous Home Next