Solved

ASP.Net SQL Update failing

Posted on 2014-11-08
3
89 Views
Last Modified: 2014-11-15
I have been trouble shooting an SQL update using a Grid View in ASP.Net.  I am at the point where I have created a simple table to verify that I can update the table using a stored procedure.   I am using VS 2010.
Create table Publisher
(PublisherID int Primary Key identity(1,1)
,PublisherName varchar(100))
go

insert into Publisher values ('Marvel')

go
Create proc PublisherSelect
@PublisherID int
as
Select PublisherID
     , PublisherName
from Publisher
go

Create proc PublisherUpdate
@PublisherID int
, @PublisherName varchar(100)
as
Update Publisher
set PublisherName = @PublisherName
where PublisherID = @PublisherID

Open in new window

I have verified that the stored procedure works on the sql server.

My data source is the following:
   
      <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:TimeCardString %>" 
        ProviderName="<%$ ConnectionStrings:TimeCardString.ProviderName %>" 
        SelectCommand="PublisherSelect" SelectCommandType="StoredProcedure" 
        UpdateCommand="PublisherUpdate" UpdateCommandType="StoredProcedure">
        <SelectParameters>
          <asp:ControlParameter ControlID="TextBox1" Name="PublisherID" 
            PropertyName="Text" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
          <asp:Parameter Name="PublisherID" Type="Int32" />
          <asp:Parameter Name="PublisherName" Type="String" />
        </UpdateParameters>
      </asp:SqlDataSource>

Open in new window

and my Grid is as follows:
      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  
        DataKeyNames="PublisherID" DataSourceID="SqlDataSource1">
        <Columns>
          <asp:CommandField ShowEditButton="True" />
          <asp:BoundField DataField="PublisherID" HeaderText="PublisherID" 
            SortExpression="PublisherID" InsertVisible="False" ReadOnly="True" />
          <asp:BoundField DataField="PublisherName" HeaderText="PublisherName" 
            SortExpression="PublisherName" />
        </Columns>
      </asp:GridView>

Open in new window


When I attempt to update the record, I get error converting data type varchar to int.   If I let the SQL wizard create the update then things work as they should.
0
Comment
Question by:ButlerTechnology
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 40431567
can you show the stord proc that updates your records?
0
 
LVL 6

Accepted Solution

by:
ButlerTechnology earned 0 total points
ID: 40432492
Sammy:

thanks for the reply on this issue.  I kept digging in to the issue.  I attempted my coding example in a different environment with success, so I attempted on a clean Project in the failing environment.  That worked.  I noticed that I was getting a non-critical error with a file in the failing environment, so I am going to assume that they are related.

Tom
0
 
LVL 6

Author Closing Comment

by:ButlerTechnology
ID: 40444279
solution was unique to the environment.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question