powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
7 сообщений из 7, страница 1 из 1
Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
    #38237845
Есть хранимая процедура на сервере:

USE [ReportsPodrSQL]
GO
/****** Объект: StoredProcedure [dbo].[GetProba] Дата сценария: 04/24/2013 11:30:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[GetProba] (@param1 int = 400401,@RowCount int output)
as
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
-- SET NOCOUNT ON;
select * from ubytki where codepodr=@param1

-- Insert statements for procedure here
SELECT @RowCount=@@ROWCOUNT
END
RETURN

В среде Microsift Sql Server Management Studio Express работает прекрасно, а вот из Visual Studio 2012 не могу запустить никак.

Пробовал так:

Private Sub btnGetAuthors_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGetAuthors.Click
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

'Create a connection to the SQL Server.
MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes")

'Create a DataAdapter, and then provide the name of the stored procedure.
MyDataAdapter = New SqlDataAdapter("GetProba", MyConnection)

'Set the command type as StoredProcedure.
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

' 'Create and add a parameter to Parameters collection for the stored procedure.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@param1", _
SqlDbType.Int, 8))

' 'Assign the search value to the parameter.
MyDataAdapter.SelectCommand.Parameters("@param1").Value = 400401

'Create and add an output parameter to Parameters collection.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@RowCount", _
SqlDbType.Int))


'Set the direction for the parameter. This parameter returns the Rows returned.
MyDataAdapter.SelectCommand.Parameters("@RowCount").Direction = ParameterDirection.Output
DS = New DataSet() 'Create a new DataSet to hold the records.
MyDataAdapter.Fill(DS, "UBY") 'Fill the DataSet with the rows returned.

'Get the number of rows returned, and then assign it to the Label control.
lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " Rows Found!"
lblRowCount.Text = MyDataAdapter.SelectCommand.Parameters(1).Value

'Set the data source for the DataGrid as the DataSet that holds the rows.
GrdAuthors.DataSource = DS.Tables("UBY").DefaultView

'Bind the DataSet to the DataGrid.
'NOTE: If you do not call this method, the DataGrid is not displayed!
Grdauthors.DataBind()

MyDataAdapter.Dispose() 'Dispose of the DataAdapter.
MyConnection.Close() 'Close the connection.
End Sub

Этот пример взят из MSDN. Все вроде должно работать.
И пробовал чепрез сервис работы с базами данных среды Microsoft Visual Studio 2012. Обращение к хранимой процедуре есть, но почему то не выполняется SELECT и не возвращаются параметры.
...
Рейтинг: 0 / 0
Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
    #38237868
cooldeveloper
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А причем тут ASP.NET?
...
Рейтинг: 0 / 0
Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
    #38238120
handmadeFromRu
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
http://stackoverflow.com/questions/3309213/getting-return-value-from-stored-procedure-in-ado-net
--Все вроде должно работать.
ну да если уметь готовить
ссыль на мснд дали бы чтоб поглядеть
...
Рейтинг: 0 / 0
Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
    #38238148
handmadeFromRu http://stackoverflow.com/questions/3309213/getting-return-value-from-stored-procedure-in-ado-net
--Все вроде должно работать.
ну да если уметь готовить
ссыль на мснд дали бы чтоб поглядеть

Вот ссылка: http://support.microsoft.com/kb/306574
...
Рейтинг: 0 / 0
Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
    #38238285
handmadeFromRu
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
о черт и это мс опубликовала....нда.
...
Рейтинг: 0 / 0
Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
    #38239640
handmadeFromRu,

Заработало вот так:



Private Sub btnGetAuthors_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGetAuthors.Click
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim ReturnValue As SqlParameter
Dim cmd As SqlCommand

'Create a connection to the SQL Server.
MyConnection = New SqlConnection("server=MSLN-KRAFT\SQL2005D;database=ReportsPodrSQL;Trusted_Connection=yes")





cmd = New SqlCommand("GetProba", MyConnection)


cmd.CommandType = CommandType.StoredProcedure
ReturnValue = New SqlParameter("@RowCount", SqlDbType.Int)
ReturnValue.Direction = System.Data.ParameterDirection.Output
cmd.Parameters.Add(ReturnValue)
MyConnection.Open()

cmd.ExecuteNonQuery()
Alert(cmd.Parameters("@RowCount").Value)
end sub
...
Рейтинг: 0 / 0
Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
    #38239716
Так тоже заработало:


Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter

'Create a connection to the SQL Server.
MyConnection = New SqlConnection("server=MSLN-KRAFT\SQL2005D;database=ReportsPodrSQL;Trusted_Connection=yes")

'Create a DataAdapter, and then provide the name of the stored procedure.
MyDataAdapter = New SqlDataAdapter("GetProba", MyConnection)

'Set the command type as StoredProcedure.
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

'Create and add a parameter to Parameters collection for the stored procedure.

'Create and add an output parameter to Parameters collection.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@RowCount", _
SqlDbType.Int, 4))

'Set the direction for the parameter. This parameter returns the Rows returned.
MyDataAdapter.SelectCommand.Parameters("@RowCount").Direction = ParameterDirection.Output

DS = New DataSet() 'Create a new DataSet to hold the records.
MyDataAdapter.Fill(DS, "AuthorsByLastName") 'Fill the DataSet with the rows returned.

'Get the number of rows returned, and then assign it to the Label control.
'lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " Rows Found!"
lblRowCount.Text = MyDataAdapter.SelectCommand.Parameters(0).Value & " Rows Found!"

'Set the data source for the DataGrid as the DataSet that holds the rows.
GrdAuthors.DataSource = DS.Tables("AuthorsByLastName").DefaultView

'Bind the DataSet to the DataGrid.
'NOTE: If you do not call this method, the DataGrid is not displayed!
GrdAuthors.DataBind()

MyDataAdapter.Dispose() 'Dispose of the DataAdapter.
MyConnection.Close() 'Close the connection.

End Sub
...
Рейтинг: 0 / 0
7 сообщений из 7, страница 1 из 1
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Выполнение хранимых процедур SQL Server 2005 в ASP.NET (Visual Studio 2012)
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]