protected void butSubmit_Click(object sender, EventArgs e) { //try //{ Byte[] imgByte = null; if(FileUpload1.HasFile && FileUpload1.PostedFile !=null) { HttpPostedFile File = FileUpload1.PostedFile; imgByte = new Byte[File.ContentLength]; File.InputStream.Read(imgByte, 0, File.ContentLength); } string cs = ConfigurationManager.ConnectionStrings["master"].ConnectionString; using( SqlConnection connection = new SqlConnection(cs)) { connection.Open(); string sql = "INSERT INTO tblImage(image) VALUES(@theImage) SELECT @@IDENTITY"; using (SqlCommand cmd = new SqlCommand(sql, connection)) { cmd.Parameters.AddWithValue("@theImage", imgByte); int id = Convert.ToInt32(cmd.ExecuteScalar()); lblStatus.Text = String.Format("Image is Uploaded successfully!! and Image ID is {0}", id); cmd.Dispose(); } connection.Close(); connection.Dispose(); }
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#Button1").click(function (e) { $('.display').text(''); //clean div display var ID = $("#txtID").val(); if (ID.length > 0) { var newImage = $('<img />'); newImage.attr('src', 'ReadImage.ashx?id=' + ID); // call handler with id $('.display').append(newImage); } e.preventDefault(); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> Display Image<br /> <br /> Id <asp:TextBox ID="txtID" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Display" /> <br /> <br /> <div class="display"></div> <br /> <br /> </div> </form>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)