powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / ADO.NET, LINQ, Entity Framework, NHibernate, DAL, ORM [игнор отключен] [закрыт для гостей] / Динамические параметры в SqlDataSource
2 сообщений из 2, страница 1 из 1
Динамические параметры в SqlDataSource
    #34360145
Red Wind
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Доброго времени суток. Пытаюсь динамически передать UpdateCommand в SqlDataSource, но из этого ничего не выходит. В событии Page_Load выполняю этот код:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
    private void CreatingCommands()
    {
        SqlConnection conn = new SqlConnection(ConnectionString);
        SqlDataAdapter adapter = new SqlDataAdapter(DynamicSqlDataSource.SelectCommand, conn);
        SqlCommandBuilder sqb = new SqlCommandBuilder(adapter);
        adapter.UpdateCommand = sqb.GetUpdateCommand(true);
        DynamicSqlDataSource.UpdateCommand = adapter.UpdateCommand.CommandText;

        //проблема в том, что тип параметров adapter не совпадает с типом SqlDataSource
        for (int i =  0 ; i <= adapter.UpdateCommand.Parameters.Count -  1 ; i++)
        {
            Parameter param = new Parameter();
            param.Name = adapter.UpdateCommand.Parameters[i].ParameterName;
            DynamicSqlDataSource.UpdateParameters.Add(param);
        }
    }
Вроде бы всё ок, UpdateCommand передаётся, параметры создаются. Но когда происходит Update, то в окне браузера выскакивает такая ошибка:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Server Error in '/WebSite3' Application.
--------------------------------------------------------------------------------

Must declare the scalar variable "@Original_ID". 
Description: An unhandled exception occurred during the execution of the current web request. 
Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@Original_ID".

Source Error: 

An unhandled exception was generated during the execution of the current web request. 
Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Самое неприятное, то что @Original_ID существует в DynamicSqlDataSource.UpdateParameters. Собственно вопрос, как мне корректно предать UpdateParameters в SqlDataSource?
...
Рейтинг: 0 / 0
Динамические параметры в SqlDataSource
    #34372801
pecha
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот это вообще бахни
автор//проблема в том, что тип параметров adapter не совпадает с типом SqlDataSource
for (int i = 0; i <= adapter.UpdateCommand.Parameters.Count - 1; i++)
{
Parameter param = new Parameter();
param.Name = adapter.UpdateCommand.Parameters .ParameterName;
DynamicSqlDataSource.UpdateParameters.Add(param);
}


И сделай вот так

DynamicSqlDataSource.UpdateParameters.Clear();
DynamicSqlDataSource.UpdateParameters.Add("Original_ID", "CЮДА ЗАСУНЬ ID");


GoDevs.com - Cheap Domain Names, Free/Cheap Windows/Linux Web Hosting (ASP.NET 1.1/2.0, MySql & MS SQL Databases) and much more! Shared Windows Web Hosting (ASP.NET 2.0) now with ASP.NET AJAX!
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / ADO.NET, LINQ, Entity Framework, NHibernate, DAL, ORM [игнор отключен] [закрыт для гостей] / Динамические параметры в SqlDataSource
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


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