请问System.Data空间下的SqlDbType枚举和System.Data.SqlTypes空间下的类型枚举,它们之间有何区别?
在什么地方用哪中枚举比较好?
在什么地方用哪中枚举比较好?
解决方案 »
- 【求助】c++ typedef struct 转换成c#类型,急!在线等!!!
- 执行insert into 插入语句,插入成功,但返回受影响的行数为-1???
- 用C#做的多国时钟
- 存储过程中怎样触发某个应用程序
- 我想用c#三层结构的oa换c#三层结构的全站程序学习。
- 我想用html的button控制一个服务器端的树控件,应该怎么弄呀,我动态的在网页里加了一个客户端的button,想
- 纠结了两天的问题,求高手回答,关于回调函数中更新Form控件的问题
- 如何用datalist 做出两个listview之间点击可以交互数据的功能
- 一个类只能由另一个类来使用其成员函数,怎么定义?
- 如何实现如此效果:单击按钮,相当于按了快捷键A键,用WPF实现
- 加载XML问题
- 问个幼稚的问题。C#能直接写网页吗?
还是有点疑惑,两者都是针对SQL Server 的数据类型,两者是不是可以相互替换?能举个例子吗?
以下代码创建 DataTable 对象,使用 System.Data.SqlTypes(而不是 CLR 类型)显式定义 DataColumn 数据类型。 代码用 SQL Server 2005 中 AdventureWorks 数据库的 Sales.SalesOrderDetail 表中的数据填充 DataTable。
static private void GetSqlTypesAW(string connectionString)
{
// Create a DataTable and specify a SqlType
// for each column.
DataTable table = new DataTable();
DataColumn icolumnolumn =
table.Columns.Add("SalesOrderID", typeof(SqlInt32));
DataColumn priceColumn =
table.Columns.Add("UnitPrice", typeof(SqlMoney));
DataColumn totalColumn =
table.Columns.Add("LineTotal", typeof(SqlDecimal));
DataColumn columnModifiedDate =
table.Columns.Add("ModifiedDate", typeof(SqlDateTime)); // Open a connection to SQL Server and fill the DataTable
// with data from the Sales.SalesOrderDetail table
// in the AdventureWorks sample database.
using (SqlConnection connection = new SqlConnection(connectionString))
{
string queryString =
"SELECT TOP 5 SalesOrderID, UnitPrice, LineTotal, ModifiedDate "
+ "FROM Sales.SalesOrderDetail WHERE LineTotal < @LineTotal"; // Create the SqlCommand.
SqlCommand command = new SqlCommand(queryString, connection); // Create the SqlParameter and assign a value.
SqlParameter parameter =
new SqlParameter("@LineTotal", SqlDbType.Decimal);
parameter.Value = 1.5;
command.Parameters.Add(parameter); // Open the connection and load the data.
connection.Open();
SqlDataReader reader =
command.ExecuteReader(CommandBehavior.CloseConnection);
table.Load(reader); // Close the SqlDataReader.
reader.Close();
} // Display the SqlType of each column.
Console.WriteLine("Data Types:");
foreach (DataColumn column in table.Columns)
{
Console.WriteLine(" {0} -- {1}",
column.ColumnName, column.DataType.UnderlyingSystemType);
} // Display the value for each row.
Console.WriteLine("Values:");
foreach (DataRow row in table.Rows)
{
Console.Write(" {0}, ", row["SalesOrderID"]);
Console.Write(" {0}, ", row["UnitPrice"]);
Console.Write(" {0}, ", row["LineTotal"]);
Console.Write(" {0} ", row["ModifiedDate"]);
Console.WriteLine();
}
}控制台窗口中显示的输出显示每个列的数据类型以及从 SQL Server 检索的值。
也可以运行,我可不可以认为System.Data.SqlTypes下的成员可以完全取代SqlDbType下的枚举 ?