Solved

ASP.Net SQL Update failing

Posted on 2014-11-08
3
86 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql server insert 12 30
TSQL - How to declare table name 26 30
MSSQL Import .SQL files - Increase Import Speed 9 36
SQL Query assistance 16 23
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

770 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