存儲過程參數datatable
㈠ c#怎麼寫帶有兩個參數的存儲過程,並把結果集填充在datatbale里
create proc sql_time
@startTime varchar(200),@endTime varchar(200)
as
BEGIN
call sp_firste_level_rate(@startTime,@endTime)
END
至於sql語句和dal層里的方法怎麼寫這個你自己整吧,到時候直接把sal語句寫成存儲過程名就可以了
㈡ 存儲過程中參數可以是datatable嗎
參數類型只能是:數字、字元、二進制等,但絕不可能包含datatable
㈢ 如何執行帶參數的存儲過程
//首先聲明一個SqlParameter數組
SqlParameter[] para=new SqlParameter[2];
//給數組賦值
para[0]=new SqlParameter("@UserName","AX");
para[1]=new SqlParameter("@stlID","hello");
//調用該方法
DataTable dt=dataTable(AXProc,para);
你這個方法好經典,從哪裡的吧,呵呵,我的項目也在用這個呢!
㈣ 需求是這樣的:我有一個DataSet,其中有一個DataTable,這個DataTable是根據調用存儲過程不同的參數而生成的
這個東西是無所謂的,不管你數據集合如果變化 添加到datatable裡面他都是不會管的。主要的問題是你需要設定你的查詢語句。
㈤ .net如何將datatable數據保存到sql資料庫
//1、使用sqlbulk.writetoserver(datatable)
SqlBulkCopysqlbulk=newSqlBulkCopy(connectionString,SqlBulkCopyOptions.UseInternalTransaction);
sqlbulk.DestinationTableName="Table_1";//資料庫中的表名
sqlbulk.WriteToServer(dataset.Tables[0]);
//2、使用sqlcommand.executenonquery()方法插入
foreach(DataRowdatarowindatatable.Rows)
{
stringsql="INSERTINTO[Table_1]
([CompanyName],[CompanyCode],[Address],[Owner],[Memo])"+
"VALUES('"+datarow["CompanyName"].ToString()+"'"+
",'"+datarow["CompanyCode"].ToString()+"'"+
",'"+datarow["Address"].ToString()+"'"+
",'"+datarow["Owner"].ToString()+"'"+
",'"+datarow["Memo"].ToString()+"')";
using(SqlConnectionsqlconn=newSqlConnection(connectionString))
{
sqlconn.Open();
SqlCommandsqlcommand=newSqlCommand(sql,sqlconn);
sqlcommand.ExecuteNonQuery();
sqlconn.Close();
}
}
使用sqldataadapter.update(dataset,tablename);
SqlCommandinsertcommand=newSqlCommand("INSERTINTO[Table_1]([CompanyName],[CompanyCode],[Address],[Owner],[Memo])"+
"VALUES(@CompanyName,@CompanyCode,@Address,@Owner,@Memo)",newSqlConnection(connectionString));
insertcommand.Parameters.Add("@CompanyName",SqlDbType.NChar,50,"CompanyName");
insertcommand.Parameters.Add("@CompanyCode",SqlDbType.NChar,25,"CompanyCode");
insertcommand.Parameters.Add("@Address",SqlDbType.NChar,255,"Address");
insertcommand.Parameters.Add("@Owner",SqlDbType.NChar,25,"Owner");
insertcommand.Parameters.Add("@Memo",SqlDbType.NChar,255,"Memo");
sqldataadapter.InsertCommand=insertcommand;
sqldataadapter.Update(dataset,"Table_1");
使用sqlbulk.writetoserver(datatable)
SqlBulkCopysqlbulk=newSqlBulkCopy(connectionString,SqlBulkCopyOptions.UseInternalTransaction);
sqlbulk.DestinationTableName="Table_1";//資料庫中的表名
sqlbulk.WriteToServer(dataset.Tables[0]);
㈥ oracle存儲過程中參數datatable如何接收,求高手!
%ROWTYPE 類型。 proce setDatetabe1(tabTest in tabel%ROWTYPE,
index in number)
{ a := tabTest(index).name;
b := tabTest(index).age;
}
㈦ 如何用ServiceStack.OrmLite執行存儲過程,並將結果以DataTable形式返回
和調用sql語句一樣,執行「exec 存儲過程名 參數1,參數2」,然後存儲過程中需要執行一個查詢語句,那麼執行存儲過程就是執行這個查詢語句,結果也就是一張表,其他的都和sql語句一樣了
㈧ 我的sql存儲過程是執行分頁查詢的 返回當前頁的數據datatable 和output輸出參數總條數pagecount能一條sql
給你個我在用的分頁存儲過程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[global.pagebreak]
@pFields varchar(4000)='*',--查詢的欄位
@pSortField varchar(2000)='',--排序的欄位
@pTable varchar(3000)='',--所查的表
@pWhere varchar(4000)='',--條件
@pOnePageRows int = 25,--每頁顯示的條數
@pIndex int = 1
as
declare @s varchar(5000)
if (@pWhere='' or @pWhere=NULL)
begin
set @s ='
DECLARE @totalRows int
DECLARE @totalPages int
SELECT @totalRows = COUNT(*) From '+@pTable+'
SET @totalPages = @totalRows / '+cast(@pOnePageRows as varchar)+'
IF( @totalPages * '+cast(@pOnePageRows as varchar) + '< @totalRows)
SELECT @totalPages = @totalPages + 1
SELECT '+@pFields+' FROM(
SELECT ROW_NUMBER() OVER(order by '+@pSortField+') as ROWID, '+@pFields+' From '+@pTable+')
AS TSP
WHERE ROWID BETWEEN '+cast((((@pIndex-1)*@pOnePageRows)+1) as varchar)+'
AND '+cast((@pIndex*@pOnePageRows) as varchar)+'
SELECT @totalRows AS TOTALROWS,
@totalPages AS TOTALPAGES,
'+cast(@pIndex as varchar)+' AS CURRENTPAGE,
'+cast(@pOnePageRows as varchar)+' AS ONEPAGEROWS '
end
else
begin
set @s ='
DECLARE @totalRows int
DECLARE @totalPages int
SELECT @totalRows = COUNT(*) From '+@pTable+' where '+@pWhere+'
SELECT @totalPages = @totalRows / '+cast(@pOnePageRows as varchar)+'
IF( @totalPages * '+cast(@pOnePageRows as varchar) + '< @totalRows)
SELECT @totalPages = @totalPages + 1
SELECT '+@pFields+' FROM(
SELECT ROW_NUMBER() OVER(order by '+@pSortField+') as ROWID, '+@pFields+' From '+@pTable+' where '+@pWhere+')
AS TSP
WHERE ROWID BETWEEN '+cast((((@pIndex-1)*@pOnePageRows)+1) as varchar)+'
AND '+cast((@pIndex*@pOnePageRows) as varchar)+'
SELECT @totalRows AS TOTALROWS,
@totalPages AS TOTALPAGES,
'+cast(@pIndex as varchar)+' AS CURRENTPAGE,
'+cast(@pOnePageRows as varchar)+' AS ONEPAGEROWS '
end
print @s
exec(@s)
㈨ c# 獲取存儲過程參數名和類型
using (var conn = new SqlConnection(ConnectionString))
{
conn.Open();
var restrictions = new string[3];
restrictions[2] = "getCourseByStudentId";
var d = conn.GetSchema("ProcereParameters", restrictions);
}
得到的d變數,是一個datatable對象,裡面有你想要的。