Please check the below code which i have marked as comment
This is my store procdure code in here all is ok but check my the asp.net code
- USE [DBBJBPL1]
- GO
- /****** Object: StoredProcedure [dbo].[fabric_ins] Script Date: 21/12/2018 12:38:34 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- ALTER procedure [dbo].[fabric_ins]
- (
-
-
-
-
-
-
-
- @fabrictype varchar(50)=null
- ,@weave varchar(50)=null
- ,@colour varchar(50)=null
- ,@lamination bit=0
- ,@gsm int=0
- ,@width decimal(18,2)=0.0
- ,@operationType int=0
- ,@itemcode varchar(10)=null
- ,@ret varchar(250) OUTPUT
- )
- AS
- BEGIN
- if @operationType=0
- begin
- BEGIN TRY
- SET NOCOUNT ON
- SET XACT_ABORT ON
- BEGIN TRANSACTION
- insert into ItemMaster(itemcd,itemdescription,width,isLaminated,GSM,colour,mtype )
- values
- (
- [dbo].[AUTO_DOC_CODE]('IC'),@fabrictype,@width,@lamination,@gsm,@colour,'FABRIC'
- )
- set @ret='S'
- UPDATE documentnumber
- SET doc_last_srl_no=SUBSTRING([dbo].[AUTO_DOC_CODE]('IC'),4,5),
- doc_suff=dbo.fnGetFiscalYear(),
- doc_no_last_update=GETDATE()
- WHERE doctype='IC' and location='01'
- COMMIT TRANSACTION
- END TRY
- BEGIN CATCH
- IF @@TRANCOUNT > 0 AND XACT_STATE() <> 0
- ROLLBACK TRAN
- SET @RET=ERROR_MESSAGE();
- END CATCH
- end
- else if @operationType=1
- begin
- select * from itemmaster where itemcd=@itemcode
- end
- else if @operationType=2
- begin
- update itemmaster set GSM=@gsm,colour=@colour,width=@width where itemcd=@itemcode
- end
-
-
-
-
- END
asp.net code
- protected void lnkdit_Click(object sender, EventArgs e)
- {
- LinkButton lnkdit = (LinkButton)sender;
- GridViewRow Grow = (GridViewRow)lnkdit.NamingContainer;
- Label lblitemcds = (Label)Grow.FindControl("lblitemcds");
- editrecords(lblitemcds.Text);
- pnladd.Visible = true;
- pnlview.Visible = false;
- }
- private void editrecords(string lblitemcds)
- {
- DataTable dt = new DataTable();
- try
- {
- if (connection.State == ConnectionState.Open)
- connection.Close();
- connection.Open();
- SqlDataAdapter sda = new SqlDataAdapter("fabric_ins", connection);
- sda.SelectCommand.CommandType = CommandType.StoredProcedure;
-
-
-
-
-
-
- sda.SelectCommand.Parameters.AddWithValue("@operationType", 1);
- sda.SelectCommand.Parameters.AddWithValue("@itemcode", lblitemcds);
- sda.SelectCommand.Parameters.Add("@ret", SqlDbType.VarChar, 250);
- sda.SelectCommand.Parameters["@ret"].Direction = ParameterDirection.Output;
- sda.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- txtgsm.Text = dt.Rows[0]["gsm"].ToString();
- ddlcolour.SelectedValue = dt.Rows[0]["colour"].ToString();
- txtwidth.Text = dt.Rows[0]["width"].ToString();
- }
- }
- catch (Exception ex)
- {
-
- }
- finally
- {
- if (connection.State == ConnectionState.Open)
- connection.Close();
- }
- }