使用存储过程将图像上载到存储数据库 [英] upload image to store database using stored procedure
本文介绍了使用存储过程将图像上载到存储数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C#代码
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
/****** Object: StoredProcedure [dbo].[ram] Script Date: 11/27/2014 10:56:03 AM ******/
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
--INSERT
else if(@Action = 'INSERT')
BEGIN
INSERT INTO getezee(username,password,mail,imagename,uploadimage,updatedby)
VALUES (@name, @pass,@mails,@paths,@upload,@update)
END
--UPDATE
else IF(@Action = 'UPDATE')
BEGIN
UPDATE getezee
SET username = @name, password = @pass
WHERE id = @eid
END
--DELETE
else IF(@Action = 'DELETE')
BEGIN
DELETE getezee
WHERE id = @eid
END
END
推荐答案
查看以下链接:
http://www.aspsnippets.com/Articles/How -to-save-insert-in-Data-in-ASPNet-using-C-and-VBNet.aspx [ ^ ]
http://www.dotnetcurry.com/showarticle.aspx?ID=129 [ ^ ]
问候,
Praneet
Hi,
Check these links:
http://www.aspsnippets.com/Articles/How-to-save-insert-Image-in-Database-in-ASPNet-using-C-and-VBNet.aspx[^]
http://www.dotnetcurry.com/showarticle.aspx?ID=129[^]
Regards,
Praneet
调试代码,看看问题出现的地方并在Google上搜索,仍然无法找到或不能明白然后在这里发布问题..
Debug the code, and see where the problem arise and search it on Google, still can't find or can't understand then post here the problem..
这篇关于使用存储过程将图像上载到存储数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文