none
Problemas com GridView + Banco de dados SQL RRS feed

  • Pergunta

  • Gurizada,

    Estou com um problema que talvez seja de fácil resolução, mas que já me deu dor de cabeça por mais de uma semana.
    Criei um banco de dados com 4 tabelas (apenas 4), a constar:
    - t_projects
    - t_users
    - t_status
    - t_production_teams

    As tabelas t_users, t_status e t_production_teams possuem apenas dois campos: id e nome (user_name, status e production_team, respectivamente).
    A tabela t_projeto possue os campos: project_id, production_manager, client_manager, status e production_team, sendo todos campos int relacionados com as respectivas chaves primárias das tabelas que representam.

    Criei um view para exibição correta dos dados com o seguinte sql:

    SELECT     dbo.t_projects.project_name AS Project, dbo.t_projects.project_id, dbo.t_projects.production_manager,
                          dbo.t_users.user_name AS [Production Manager], dbo.t_projects.client_manager, t_users_1.user_name AS [Client Manager],
                          dbo.t_projects.production_team, dbo.t_production_teams.production_team_name AS [Production Team], dbo.t_projects.status AS status_id,
                          dbo.t_status.status
    FROM         dbo.t_status INNER JOIN
                          dbo.t_production_teams INNER JOIN
                          dbo.t_users INNER JOIN
                          dbo.t_projects ON dbo.t_users.user_id = dbo.t_projects.production_manager INNER JOIN
                          dbo.t_users AS t_users_1 ON dbo.t_projects.client_manager = t_users_1.user_id ON
                          dbo.t_production_teams.production_team_id = dbo.t_projects.production_team ON dbo.t_status.status_id = dbo.t_projects.status

    Considerando que abro duas vezes a tabela t_users pois o production_manager e o client_manager buscam dados nesta tabela.

    A exibição ocorre normalmente. Para atualização dos dados eu abro apenas a tabela t_projects (possibilitando a edição de todos os valores), da seguinte forma:

    UPDATE t_projects SET project_name =, production_manager =, client_manager =, production_team =, status =, schedule =, deadline =, details =

    Converti os campos em templates e substitui os textbox por dropdown lists exibindo os itens das tabelas. Criei todos os databindings e, no momento de clicar em update, recebo uma mensagem de erro.

    Server Error in '/ProductionChart2' Application.

    Incorrect syntax near ','.

    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: Incorrect syntax near ','.


    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.

    Stack Trace:

    [SqlException (0x80131904): Incorrect syntax near ','.]
       System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
       System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +186
       System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121
       System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
       System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +407
       System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +149
       System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +493
       System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +919
       System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +179
       System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1140
       System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +835
       System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +162
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
       System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +118
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +107
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +175
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

    Alguém poderia me ajudar a criar um update nessas condições? Valeu!

    quinta-feira, 3 de agosto de 2006 14:28

Respostas

  • Oi Raphael,

    Tente usar Parameters no seu Update string.

    UPDATE t_projects SET project_name = @project_name, production_manager = @production_manager ...

    E passe os valores para o seu objeto Command, tipo oComm.Parameters.AddWithValue ("@Project_name","Meu }Projeto") ...

    quarta-feira, 9 de agosto de 2006 16:51