C# code
protected void Button1_Click1(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string pathName = "userimage/" + filename;
FileUpload1.SaveAs(Server.MapPath("userimage/" + filename));
if (FileUpload1.HasFile)
{
con = new SqlConnection(strcon);
cmd = new SqlCommand("ram", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Parameters.AddWithValue("@Action", "INSERT");
cmd.Parameters.AddWithValue("@name", TextBox2.Text);
cmd.Parameters.AddWithValue("@pass", TextBox3.Text);
cmd.Parameters.AddWithValue("@mails", TextBox4.Text);
cmd.Parameters.AddWithValue("@upload", filename);
cmd.Parameters.AddWithValue("@paths", pathName);
cmd.Parameters.AddWithValue("@update", DateTime.Now);
cmd.ExecuteNonQuery();
con.Close();
FillGrid();
lblMessage.Text = "registered sucess";
Response.Redirect("~/register.aspx");
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Registered successfully..!! ');", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Please select a file to upload ');", true);
}
}
stored procedure
USE [prakash]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ram]
(
@eid int=0,
@name varchar(50)='',
@pass varchar(50)='',
@mails nvarchar(50)='',
@paths nvarchar(50)='',
@upload varchar(MAX)='',
@update datetime='',
@Action as varchar(50)=''
)
AS
BEGIN
SET NOCOUNT ON;
if(@Action='display')
begin
SELECT *FROM getezee
END
else if(@Action = 'INSERT')
BEGIN
INSERT INTO getezee(username,password,mail,imagename,uploadimage,updatedby)
VALUES (@name, @pass,@mails,@paths,@upload,@update)
END
else IF(@Action = 'UPDATE')
BEGIN
UPDATE getezee
SET username = @name, password = @pass
WHERE id = @eid
END
else IF(@Action = 'DELETE')
BEGIN
DELETE getezee
WHERE id = @eid
END
END