Note that there are some explanatory texts on larger screens.

plurals
  1. POIndex was outside the bounds of the array
    text
    copied!<p>In my project I am Uploading some files SQL Server, when the files are uploaded in the table <strong>Table1</strong> another function will check that Table <strong>Table1</strong> for files and inserts the Random Number or Characters into a table <strong>Table2</strong> by getting the Random Numbers or Characters from another function which generates and returns it as string, now my problem is that the Files are correctly Uploading and saving in the <strong>Table1</strong> but when <strong>Table1</strong> is inserted with files the other function which inserts Random Numbers / Character initiates but throws the Exception My Code is,</p> <pre><code> public class Upload : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Expires = -1; try { HttpPostedFile postedFile = context.Request.Files["Filedata"]; string savepath = ""; string tempPath = ""; tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; savepath = context.Server.MapPath(tempPath); string filename = postedFile.FileName; string ext = Path.GetExtension(filename); string contenttype = String.Empty; switch (ext) { case ".doc": contenttype = "application/vnd.ms-word"; break; case ".docx": contenttype = "application/vnd.ms-word"; break; case ".pdf": contenttype = "application/pdf"; break; } context.Response.StatusCode = 200; byte[] b = ReadFile(postedFile); ExamManagement.SP.QUESTIONPAPER_SP_UPLOAD(filename, contenttype,b).Execute(); trigger(); } catch (SqlException exp) { if (exp.Message.Contains("PK_answerkey")) { context.Response.Write("File Already Uploaded....."); } } catch (Exception ex) { context.Response.Write("Error: " + ex.Message); } } public bool IsReusable { get { return false; } } private byte[] ReadFile(HttpPostedFile fObj2) { byte[] data = new Byte[fObj2.ContentLength]; fObj2.InputStream.Read(data, 0, fObj2.ContentLength); return data; } protected void ClientMessaging(string msg) { String script = String.Format("alert('{0}');", msg); Anthem.Manager.IncludePageScripts = true; } protected void trigger() { try { DataSet ds = ExamManagement.SP.Questionpaper_SP_Selectall().GetDataSet(); if (ds.Tables[0].Rows.Count &gt; 0) { string a = RandomNumberGenerator(4); string b = RandomNumberGenerator(4); string c = RandomNumberGenerator(4); ExamManagement.SP.Passkey_insert(a, b, c).Execute(); } } catch { throw; **// Exception Was Thrown Here** } } public static string RandomNumberGenerator(int length) { System.Security.Cryptography.RandomNumberGenerator rng = System.Security.Cryptography.RandomNumberGenerator.Create(); char[] chars = new char[length]; //based on your requirment you can take only alphabets or number string validChars = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXzZ"; for (int i = 0; i &lt; length; i++) { byte[] bytes = new byte[1]; rng.GetBytes(bytes); Random rnd = new Random(bytes[0]); chars[i] = validChars[rnd.Next(0, 61)]; } return (new string(chars)); } </code></pre> <p>} Can Some Body Help me out... Thanks in Advance.... Error comes in this Part of the Code...</p> <pre><code> protected void trigger() { try { DataSet ds = ExamManagement.SP.Questionpaper_SP_Selectall().GetDataSet(); if (ds.Tables[0].Rows.Count &gt; 0) { string a = RandomNumberGenerator(4); string b = RandomNumberGenerator(4); string c = RandomNumberGenerator(4); ExamManagement.SP.Passkey_insert(a, b, c).Execute(); } } catch { throw; **// Exception Was Thrown Here** } } public static string RandomNumberGenerator(int length) { System.Security.Cryptography.RandomNumberGenerator rng = System.Security.Cryptography.RandomNumberGenerator.Create(); char[] chars = new char[length]; //based on your requirment you can take only alphabets or number string validChars = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXzZ"; for (int i = 0; i &lt; length; i++) { byte[] bytes = new byte[1]; rng.GetBytes(bytes); Random rnd = new Random(bytes[0]); chars[i] = validChars[rnd.Next(0, 61)]; } return (new string(chars)); } </code></pre> <p>The Passkey_insert SP is,</p> <pre><code> Create Procedure Passkey_insert ( @red varchar(100), @green varchar(100), @blue varchar(100) ) as BEGIN BEGIN TRY Insert into Passkeys(Red,Green,Blue) values (@red,@green,@blue) END TRY BEGIN CATCH IF @@TRANCOUNT &gt; 0 ROLLBACK DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int SELECT @ErrMsg = ERROR_MESSAGE(), @ErrSeverity = ERROR_SEVERITY() RAISERROR(@ErrMsg, @ErrSeverity, 1) END CATCH END </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload