.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

stored procedure is not getting invoked on update command of grid view

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net
 

Hello everybody!

In my project I am using a grid view to display data from multiple tables and I want to update that data on clicking edit button.

For selecting data I am using custom select statement, but for updating I have created a stored procedure which should update two different tables.

 

But when I click on update , it's not executing the stored procedure.

 

here is the code snippet of sqldatasource:-

<asp:SqlDataSource ID="SqlDataSource1" runat="server"  UpdateCommand="editEmployeeInfo" UpdateCommandType="StoredProcedure">

                <UpdateParameters>

                    <asp:Parameter Name="empId" Type="Int32" />

                    <asp:Parameter Name="name" Type="String" />

                    <asp:Parameter Name="address1" Type="String" />

                    <asp:Parameter Name="address2" Type="String" />

                    <asp:Parameter Name="telNo" Type="String" />

    


View Complete Post


More Related Resource Links

update two tables from single grid view using stored procedure PLZ help

  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace INV_DN
{
    public partial class Form1 : Form
    {
        SqlConnection con;
        SqlDataAdapter da1;
        SqlCommand cmd;
        //  SqlCommandBuilder cb;
        DataSet ds;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            con = new SqlConnection("User Id=sa;Password=123;database=amar");
            cmd = new SqlCommand("getdata", con);

Getting multiple rows from oracle stored procedure and binding it to grid view

  

 

To  get this stuff you need to create a Ref Cursor to return recordset.

             create or replace PACKAGE Types AS

            TYPE cursor_type IS REF CURSOR;

            END Types;

Now create a stored procedure to return multiple rows .

           create or replace

           PROCEDURE getAllCity(p_recordset OUT types.cursor_type) AS

           BEGIN

           OPEN p_recordset FOR

    

Selecting VIEW dynamically from a stored procedure

  
What's the best way to dynamically reference a view in a sproc? I want to pass a View Name into a stored procedure, but I'm guessing this is only possible with a table in SQL Server 2008. Is the only way to do this through dynamic SQL (passing in the View name as a string, and executing the query as a built string)?. My concern is that if I use Dynamic SQL, what performance gain I might get by using a view may be undone by using Exec('string').   Any thoughts?   Thanks Steve

Grid view update error

  
Server Error in '/WebSite6' Application. Object reference not set to an instance of an object. 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.NullReferenceException: Object reference not set to an instance of an object. Source Error: The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:1. Add a "Debug=true" directive at the top of the file that generated the error. Example:   <%@ Page Language="C#" Debug="true" %>or:2) Add the following section to the configuration file of your application:<configuration>    <system.web>        <compilation debug="true"/>    </system.web></configuration> Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.Important: Running applicatio

Update Database Record using GridView and Stored Procedure

  
Hi, I am trying to update record via stored procedure, but i got error at very start point. Problem is when i click on Edit link button within the Gridview it produce error. I can populate values from database fine but its produce error when i click on edit link button. Please see the code below. *********** ASP.net GridView Code I am using *****************<asp:GridView ID="GridView1" runat="server" DataKeyNames="RollID, EmpID" AutoGenerateColumns="False" Width="700px"> <Columns> <asp:TemplateField HeaderText="ApplicationID" Visible="false"> <ItemTemplate> <asp:Label ID="AppsID" runat="server" Visible="false"><%# Eval("RollID") %>'</asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="ReleaseID" Visible="false"> <ItemTemplate> <asp:Label ID="rlsID" runat="server" Visible="false"><%# Eval("EmpID") %></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Roll Name"> <ItemTemplate> <asp:Label ID="rlsVersion" runat="server"><%# Eval("Roll_Name")%></asp:Label> </ItemTemplate> <EditI

SqlDataSource, FormView, and Update with stored procedure in code behind

  
Hello, Using a FormView with a SqlDataSource, I'm attempting to Update data by calling a stored proc in code behind. I was having trouble getting parameters using Update Parameters in the SqlDataSource, but found a working solution by coding the parameters. The problem now is I'm getting an "Updating is not supported by data source 'XYZ' unless UpdateCommand is specified'. I saw some previous posts on the forums, but didn't find them very enlightening. 

Row Command Event (Grid View) and PostBack

  
I have a grid view with a number of columns in Page1.aspx.The last column is a template field with a button. On it's row command event,The control is transferred to Page2.aspx.  Initially, I had not put the PostBack property in Page1.aspx and when I used breakpoint in the RowCommand event the control never entered inside the event.However,it worked fine once I did the postback property. Can anyone explain why did this happen?  I have a grid view with a number of columns in Page1.aspx.The last column is a template field with a button.On it's row command event,The control is transferred to Page2.aspx. Initially, I had not put the PostBack property in Page1.aspx and when I used breakpoint in the RowCommand event the control never entered inside the event.However,it worked fine once I did the postback property.Can anyone explain why did this happen?  

update stored procedure for existing values of column(salperyr)

  
tbl_salary salary           salperyr   hike20      hike20yr10000.0000    NULL      12000.00    144000.0012000.0000    NULL      14400.00    172800.0014000.0000    NULL      16800.00    201600.0015000.0000    NULL      18000.00    216000.0018000.0000    NULL      21600.00    259200.0020000.0000    NULL      24000.00    288000.0022000.0000    NULL      26400.00    316800.00in above table salaryper yr (salperyr) has to be modified after caliculation my null values has to be removed and place (salary*12)in one shot.so plz suggest me update stored procedure for this.

update stored procedure for existing values of column(

  
tbl_salary salary            salperyr    hike20       hike20yr 10000.0000    NULL      12000.00    144000.00 12000.0000    NULL      14400.00    172800.00 14000.0000    NULL      16800.00    201600.00 15000.0000    NULL      18000.00    216000.00 18000.0000    NULL      21600.00    259200.00 20000.0000    NULL      24000.00    288000.00 22000.0000    NULL      26400.00    316800.00 in above table salaryper yr (salperyr ) has to be modified after caliculation my null values has to be removed and place (salary*12 )in one shot.   so plz suggest me update stored procedure for this

stored procedure: select and update

  
Is it possible to use a stored procedure to get a value of the database, change it and save it back at ones? Let me show a simple example: In the databse I have an integer value (20). Then I get another number (5), and I would like to subtract it of the  value from database (20 - 5). That means I have to get the value 20 out of the database, of it subtract value 5, and insert (update) new value (15) back to the database. Or is it not even necessary to get the value 20 out of the databse, but only directly subtract value 5 of the value in the database? Is this possible to do with stored procedure?

how to update a Grid view using Ajex

  

how to update a Grid view using Ajex



my query is select * From erp where emp>10;


then update the grdi view using ajex if any button Click


unable to update data to databse from grid view

  

I have two tables in my database

using "innerconnect" i have show table content in grid view as      INV_NO            INV_DT        DN_NO       DN_DT   LR_NO        LR_DT .

where LR_NO is null .

I want to update it from grid view plz help




TABLES









here  DN_NO  and INV_NO are primary keys

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace amar
{
    public partial class Form2 : Form
    {
        SqlConnection con;
        SqlDataAdapter da1,da2;
        SqlCommandBuilder cb;
    &nb

SQL Stored Procedure - if exists Update else Insert.

  

Hey,

I'm trying to create a stored procedure that get a Key and Name (both varchar), the procedure will check if a the key allready exists in the table, if it exists it will update the name, if its not exists it will add it to the table..

I have no clue how to use IF to check if the row exists, please help.


Thanks :)


SQL Command Or Stored Procedure in Execute SQL Task

  

Hi all,

Which is a better way to do in Execute SQL Task : Direct SQL input or Create a stored proc in database and then use that.

In my opinion, Stored Procedure is a better and recommended way for following reasons:

  • Cached execution plan
  • More secure
  • Centralized code
  • Code reuse

Please let me know if this is not the case with SSIS Execute SQL Task.

Thanks!


Grid view update problem in asp.net c#

  

Here is my complete code.....please tel where is the problem as i want to update the row in gridview.....and my textbox txtBox1,txtBox2,txtBox3 are having null .........and i'm getting error on the line SqlCommand cmd = new SqlCommand("update product set prodname = '" + txtBox2.Text + "' , proddesc = '" + txtBox3.Text + "' where prodid = " + txtBox1.Text + "", conn); saying that 

 

Object reference not set to an instance of an object.



public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnadd_Click(object sender, EventArgs e)
    {
        
        string pname=txtprodname.Text;
        string pdesc=txtdesc.Text;
        SqlConnection conn = new SqlConnection("Data Source=ABC-59236A7CB6F;Initial Catalog=practical2;Integrated Security=True");
        conn.Open();
         SqlCo

Stored Procedure failed after underlying view got changed

  

Yesterday I came across a situation where after an underlying view was altered to add a new column(view is a simple select statement) the stored procedure using that view failed giving some conversion error. the stored procedure does not use * but uses explicit column names. 

even after recompiling the SP with sp_recompile the issue was not solved.

we then dropped stored procedure and recreated it (using same script). And it ran sucessfully.

Any specific reasons for this behaviour. I have an understanding that stored procedure should have got recompiled automatically.

 


insert and update from a same stored procedure

  

in sql server 2005

hi i am creating  a stored procedure for a inserting and updating a table as follows

where id is identity.

my intention is when i supply the id value  then it performs update other wise it goes to insert

my table is as

CREATE TABLE [dbo].[TblAccountType](
    [id] [tinyint] IDENTITY(1,1) NOT NULL,
    [AccType] [varchar](20) NOT NULL,
    [Description] [varchar](max)  NULL)

and stored procedure is

 

 

create  proc [dbo].[SppInsertAccType]
(@id as tinyint =null,
@AccType as varchar(20),
@Description as varchar(max))
as
begin
set nocount on
set transaction isolation level read uncommitted
begin tran
 if exists(select id from TblAccountType where id=@id)
begin
update TblAccountType set AccType=@AccType,Description=@Description where id=@id
end
else
begin
insert into TblAccountType(AccType,Description)values(@AccType,@Description)
end
commit tran
end


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend