Solved

ASP.Net SQL Update failing

Posted on 2014-11-08
3
81 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
  • 2
3 Comments
 
LVL 28

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now