Link to home
Create AccountLog in
Avatar of ButlerTechnology
ButlerTechnology

asked on

ASP.Net SQL Update failing

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.
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

can you show the stord proc that updates your records?
ASKER CERTIFIED SOLUTION
Avatar of ButlerTechnology
ButlerTechnology

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of ButlerTechnology
ButlerTechnology

ASKER

solution was unique to the environment.