⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 14.5.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 14.5 Adding New DataRows
using System;
using System.Data;
namespace _14_DataRows
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
char input;
// create inventory table
DataTable table = new DataTable(“Inventory”);
// add primary key column
DataColumn col = new DataColumn( “ID”, typeof(int) );
col.AutoIncrement = true;
col.Unique = true;
table.Columns.Add( col );
table.PrimaryKey = new DataColumn[]{col};
// create item and count columns
table.Columns.Add( new DataColumn(“Item”, typeof(string) ));
table.Columns.Add( new DataColumn(“Count”, typeof(int) ));
do
{
Console.WriteLine();
Console.WriteLine( “A)dd new record” );
Console.WriteLine( “M)odify record” );
Console.WriteLine( “D)elete record” );
Console.WriteLine( “V)iew records” );
Console.WriteLine( “Q)uit” );
Console.Write( “Enter command: “ );
input = Char.ToUpper(Console.ReadLine()[0]);
switch( input )
{
case( ‘A’ ):
{
DataRow row = table.NewRow();
Console.Write( “Enter item name: “ );
row[“Item”] = Console.ReadLine();
Console.Write( “Enter item count: “ );
row[“Count”] = Int32.Parse( Console.ReadLine() );
table.Rows.Add( row );
break;
}
case( ‘M’ ):
{
break;
}
case( ‘D’ ):
{
break;
}
case( ‘V’ ):
{
DataRow[] currRows = table.Select(null,
null, DataViewRowState.CurrentRows);
if (currRows.Length < 1 )
Console.WriteLine(“No Current Rows Found”);
else
{
foreach (DataColumn myCol in table.Columns)
Console.Write(“\t{0}”, myCol.ColumnName);
Console.WriteLine(“\tRowState”);
foreach (DataRow myRow in currRows)
{
foreach (DataColumn myCol in table.Columns)
Console.Write(“\t{0}”, myRow[myCol]);
Console.WriteLine(“\t” + myRow.RowState);
}
}
break;
}
case( ‘Q’ ):
{
break;
}
default:
{
Console.WriteLine( “Invalid command” );
break;
}
}
} while( input != ‘Q’ );
}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -