C#中“parameter”类的用法
2008-04-23 16:41
344 查看
MSDN 里有大把例子,如
// Assumes that connection represents a SqlConnection object.
SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT CategoryID, CategoryName FROM dbo.Categories", connection);
adapter.InsertCommand = new SqlCommand("InsertCategory", connection);
adapter.InsertCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameter = adapter.InsertCommand.Parameters.Add(
"@RowCount", SqlDbType.Int);
parameter.Direction = ParameterDirection.ReturnValue;
adapter.InsertCommand.Parameters.Add(
"@CategoryName", SqlDbType.NChar, 15, "CategoryName");
parameter = adapter.InsertCommand.Parameters.Add(
"@Identity", SqlDbType.Int, 0, "CategoryID");
parameter.Direction = ParameterDirection.Output;
DataSet categoriesDS = new DataSet();
adapter.Fill(categoriesDS, "Categories");
DataRow newRow = categoriesDS.Tables["Categories"].NewRow();
newRow["CategoryName"] = "New Category";
categoriesDS.Tables["Categories"].Rows.Add(newRow);
adapter.Update(categoriesDS, "Categories");
Int32 rowCount = (Int32)adapter.InsertCommand.Parameters["@RowCount"].Value;
// Assumes that connection represents a SqlConnection object.
SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT CategoryID, CategoryName FROM dbo.Categories", connection);
adapter.InsertCommand = new SqlCommand("InsertCategory", connection);
adapter.InsertCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameter = adapter.InsertCommand.Parameters.Add(
"@RowCount", SqlDbType.Int);
parameter.Direction = ParameterDirection.ReturnValue;
adapter.InsertCommand.Parameters.Add(
"@CategoryName", SqlDbType.NChar, 15, "CategoryName");
parameter = adapter.InsertCommand.Parameters.Add(
"@Identity", SqlDbType.Int, 0, "CategoryID");
parameter.Direction = ParameterDirection.Output;
DataSet categoriesDS = new DataSet();
adapter.Fill(categoriesDS, "Categories");
DataRow newRow = categoriesDS.Tables["Categories"].NewRow();
newRow["CategoryName"] = "New Category";
categoriesDS.Tables["Categories"].Rows.Add(newRow);
adapter.Update(categoriesDS, "Categories");
Int32 rowCount = (Int32)adapter.InsertCommand.Parameters["@RowCount"].Value;
相关文章推荐
- C#中SqlParameter的作用与用法
- C#中SqlParameter的作用与用法
- 详解C#中SqlParameter的作用与用法
- C#中SqlParameter的作用与用法
- C#中SqlParameter的作用与用法
- [C#]ADO.NET #3 (GridView + SqlDataSource)完全手写、后置程序代码,兼论 SqlDataSource与UpdateParameter/DeleteParameter的用法
- Concept Of Optional Parameter in C# 4.0
- C# List用法
- C#字符串split函数的用法,单个字符的处理示例
- C#中sqlcommand中的用法
- 全面解读C#编程中的析构函数用法
- C#中Dictionary的用法
- 自动生成C# 年月日加流水号的单据号、及日期时间相关函数的用法
- C#中ToString() 的一些常用用法
- C# IEnumberable 的用法
- C#中Dictionary的用法及用途实例
- C#中HashTable的用法 (转)
- C#中一些字符串操作的常用用法
- C#中Substring的用法说明
- ASP.NET C#中Application的用法教程