I have a two procedure, first one for Insert and the second one for update, When I update the table using "prcImage", it doesn't update. Can anyone help me to solve this. I provide the table and store procedures check it and also I provide the .cs Code

Md Khalid Hossain 0 Reputation points
2025-01-22T21:25:30.67+00:00

This is my table

CREATE TABLE [dbo].UserProfile ON [PRIMARY]

This is my 1st Store Procedure

ALTER proc [dbo].[prcDataSubmit]

@fname varchar(20),

@lname varchar(10),

@contact char(15),

@password varchar(50)

as

begin

declare @yy char(4)

declare @mm char(2)

declare @dd char(2)

declare @UserID varchar(50)

declare @tUserID numeric(15)



declare @Email char(40)

declare @Address varchar(40)

declare @City varchar(20)

declare @State varchar(20)

declare @PIN char(6)

declare @Country varchar(20)

declare @Education varchar(30)

declare @Religion varchar(10)

declare @IDproofName varchar(10)

declare @IDproofNum char(12)

declare @Pid char(20)

declare @Path char(150)

declare @Gender varchar(6)

declare @Occupation varchar(30)

declare @PhysicalAppearance varchar(20)

declare @BloodGroup char(5)

declare @MotherTounge varchar(15)

declare @Height char(5)

declare @Weight char(5)

--declare @Hour char(2)

--declare @Minute char(2)

--declare @Second char(2)

--declare @Microsecond char(3)

--set @Hour=DATEPART(HOUR,GETDATE())

--set @Minute=DATEPART(MINUTE,GETDATE())

--set @Second=DATEPART(SECOND,GETDATE())

--set @Microsecond=left(DATEPART(MICROSECOND,getdate()),3)

set @yy=year(getdate())

set @mm=month(getdate())

if len(@mm)=1

	set @mm=concat('0',@mm)

set @dd=day(getdate())

if len(@dd)=1

	set @dd=concat('0',@dd)

if exists(select * from UserProfile where dd=@dd and mm=@mm and yyyy=@yy)

begin

	select @tUserID=max(UserID) from UserProfile where dd=@dd and mm=@mm and yyyy=@yy

	set @tUserID=@tUserID+1

	set  @UserID=@tUserID

end

else

	set  @UserID=concat(@yy,@mm,@dd,'001')

insert into LogIn values (@UserID,@password)



insert into UserProfile (

    UserId, FirstName, LastName, Email, Contact, Address, City, State, PIN, Country,

    Education, Religion, IDproofName, IDproofNum, Pid, Path, Gender, Occupation,

    PhysicalAppearance, BloodGroup, MotherTounge, Height, Weight, DD, MM, YYYY

)

VALUES (

    @UserID, @fname, @lname, NULL, @contact, NULL, NULL, NULL, NULL, NULL,

    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

    NULL, NULL, @dd, @mm, @yy

)

select @UserId

end

This is my 2nd Store Procedure

ALTER proc [dbo].[prcImage] @Path char(150) as begin

declare @fname varchar(20)
declare @lname varchar(10)
declare @contact char(15)
declare @UserID varchar(50)
declare @Email char(40)
declare @Address varchar(40)
declare @City varchar(20)
declare @State varchar(20)
declare @PIN char(6)
declare @Country varchar(20)
declare @Education varchar(30)
declare @Religion varchar(10)
declare @IDproofName varchar(10)
declare @IDproofNum char(12)
declare @Pid char(20)
declare @Gender varchar(6)
declare @Occupation varchar(30)
declare @PhysicalAppearance varchar(20)
declare @BloodGroup char(5)
declare @MotherTounge varchar(15)
declare @Height char(5)
declare @Weight char(5)
declare @yy char(4)
declare @mm char(2)
declare @dd char(2)
declare @Hour char(2)
declare @Minute char(2)
declare @Second char(2)
declare @Microsecond char(3)

declare @tpid int

set @yy=year(getdate())
set @mm=month(getdate())
if len(@mm)=1
	set @mm=concat('0',@mm)

set @dd=day(getdate())
if len(@dd)=1
	set @dd=concat('0',@dd)

set @hour=DATEPART(hour,getdate())
if len(@hour)=1
	set @hour=concat('0',@hour)

set @minute=DATEPART(MINUTE,getdate())
if len(@minute)=1
	set @minute=concat('0',@minute)

set @second=DATEPART(SECOND,getdate())
if len(@second)=1
	set @second=concat('0',@second)

set @microsecond=right(DATEPART(MICROSECOND,getdate()),3)

--set @microsecond=DATEPART(MICROSECOND,getdate())
if len(@microsecond)=1
	set @microsecond=concat('00',@microsecond)
 else if len(@microsecond)=2
	set @microsecond=concat('0',@microsecond)

if exists(select * from UserProfile where dd=@dd and mm=@mm and yyyy=@yy and hour=@hour and minute=@minute and second=@second and microsecond=@microsecond)
begin
	select @tpid=max(@Pid) from UserProfile where dd=@dd and mm=@mm and yyyy=@yy and hour=@hour and minute=@minute and second=@second
	set @tpid=@tpid+1
	set  @pid=@tpid
end
else
	set  @Pid=concat(@yy,@mm,@dd,@hour,@minute,@second,@microsecond)


Update UserProfile set Email=@Email,
					   Address=@Address,
					   City=@City,
					   State=@State,
					   PIN=@PIN,
					   Country=@Country,
					   Education=@Education,
					   Religion=@Religion,
					   IDproofName=@IDproofName,
					   IDproofNum=@IDproofNum,
					   Pid=@Pid,
					   Path=@path,
					   Gender=@Gender,
					   Occupation=@Occupation,
					   PhysicalAppearance=@PhysicalAppearance,
					   BloodGroup=@BloodGroup,
					   Height=@Height,
					   Weight=@Weight,
					   DD=@dd,
					   MM=@mm,
					   YYYY=@yy,
					   Hour=@Hour,
					   Minute=@Minute,
					   Second=@Second,
					   Microsecond=@Microsecond
					   Where UserId=@UserID

select @Pid

end

This is my C# code

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.IO;

namespace Test { public partial class EnterDetails : System.Web.UI.Page { SqlConnection mycon; SqlCommand mycom; SqlDataReader dr; protected void Page_Load(object sender, EventArgs e) { mycon = new SqlConnection("server=HP;database=Project2;uid=sa;pwd=123456789"); }

    protected void btnShow_Click(object sender, EventArgs e)
    {
        string picid = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
        FileUpload1.PostedFile.SaveAs(Server.MapPath("~/TemImage/" + picid + ".jpg"));
        Image1.ImageUrl = "~/TemImage/" + picid + ".jpg";
        Label1.Text = Server.MapPath(Image1.ImageUrl);
    }

    protected void btnClear_Click(object sender, EventArgs e)
    {
        string picPath = Server.MapPath(Image1.ImageUrl);
        Image1.ImageUrl = "";
        File.Delete(picPath);
        //Label1.Text = picPath;
        Label1.Text = "";
    }

    protected void btnSub_Click(object sender, EventArgs e)
    {
        string fileName = Path.GetFileName(Image1.ImageUrl);
        //string fileName = Path.GetExtension(Image1.ImageUrl);
        Label1.Text = fileName;

        string picPath = "~/image/" + fileName;
        File.Copy(Server.MapPath(Image1.ImageUrl), Server.MapPath("~/image/" + fileName));
        btnClear_Click(sender, e);

        mycon.Open();
        mycom = new SqlCommand("exec prcImage '" + picPath + "'", mycon);
        dr = mycom.ExecuteReader();
        if (dr.Read())
            Label1.Text = dr[0].ToString();

        mycon.Close();
    }

    protected void btnSkip_Click(object sender, EventArgs e)
    {
       
    }
}

}

**Insert work properly, when I trying my second page(provided cs code for second page) for update it doesn't any respond.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,582 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,395 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.