展开全部
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;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询