protected void Button1_Click(object sender, EventArgs e)
{
string collection = "abcdefghijklmnopqrstuvwxyz123456789";
string key1 = "";
Random rnd = new Random();
for (int i = 0; i < 5; i++)
{
int k1 = rnd.Next(collection.Length);
key1 += collection.Substring(k1, 1);
}
string password = key1;
HashAlgorithm hash = new SHA256Managed();
byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes(password);
byte[] hashBytes = hash.ComputeHash(plainTextBytes);
string hashValue = Convert.ToBase64String(hashBytes);
Label2.Text = hashValue;
SqlCommand cmd = new SqlCommand("insert into HashKey values('" + Label2.Text + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(Request.PhysicalApplicationPath.ToString() + @"\Files\" + FileUpload1.FileName.ToString());
FileInfo fii = new FileInfo(Request.PhysicalApplicationPath.ToString() + @"\Files\" + FileUpload1.FileName);
Label4.Text = fii.Name.ToString();
Label5.Text = fii.Length.ToString() + "Bytes";
string input = Request.PhysicalApplicationPath.ToString() + @"\Files\" + FileUpload1.FileName;
string output=Request.PhysicalApplicationPath.ToString() + @"\Encrypt\" + FileUpload1.FileName;
Encrypt(input,output);
string random = "0123456789";
string key2 = "";
Random ran = new Random();
for (int i = 0; i < 4; i++)
{
int k2 = ran.Next(random.Length);
key2 += random.Substring(k2, 1);
}
SqlCommand cmnd = new SqlCommand("insert into Upload(ID,Filename,Filesize,Keyword,Data) values('"+key2+"','" + Label4.Text + "','" + Label5.Text + "','" + TextBox1.Text + "','"+output+"')", con);
con.Open();
int k=cmnd.ExecuteNonQuery();
if (k > 0)
{
SqlCommand cmnd2 = new SqlCommand("select Keyword from Upload where Keyword=@keyword",con);
cmnd2.Parameters.AddWithValue("@keyword",TextBox1.Text);
using (SqlDataReader dr = cmnd2.ExecuteReader())
{
if (dr == null)
{
SqlCommand cmnd3 = new SqlCommand("insert into Index_list(ID,Keyword) values('"+key2+"','"+TextBox1.Text+"')", con);
cmnd3.ExecuteNonQuery();
}
else
{
SqlConnection connection = new SqlConnection(@"Data Source=gateway-PC;Initial Catalog=Blindstore;Integrated Security=True");
SqlCommand cmnd4 = new SqlCommand("UPDATE t SET ID = STUFF( (SELECT ',' + CAST(ID AS VARCHAR(100)) [text()] FROM Upload f WHERE t.Keyword = f.Keyword FOR XML PATH(''),TYPE).value('.','NVARCHAR(MAX)'), 1, 1, '') FROM Index_list t ", connection);
connection.Open();
cmnd4.ExecuteNonQuery();
}
Response.Write("");
}
}
}
}
Insert query (cmnd3) does not work , please help me!!!


Shubham KumarRank #621 · 3.8K reputationPosted Feb 18, 2016, 1:49 AM EST
Shubham KumarRank #621 · 3.8K reputationPosted Feb 18, 2016, 8:19 PM EST
Shubham KumarRank #621 · 3.8K reputationPosted Feb 18, 2016, 10:35 PM EST
Shubham KumarRank #621 · 3.8K reputationPosted Feb 19, 2016, 8:22 PM EST
Rafnas T PRank #280 · 8.8K reputationPosted Feb 19, 2016, 11:52 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Feb 17, 2016, 11:01 PM EST
Do you receive any message? What does it say?
You might be inserting same value to ID column in Index_list. ( I assumed ID is column is unique)
Shubham KumarRank #621 · 3.8K reputationPosted Feb 18, 2016, 12:41 AM EST
Saafia NM56 reputationPosted Feb 18, 2016, 12:59 AM EST
Shubham KumarRank #621 · 3.8K reputationPosted Feb 18, 2016, 1:08 AM EST
Saafia NM56 reputationPosted Feb 18, 2016, 1:19 AM EST
Rafnas T PRank #280 · 8.8K reputationPosted Feb 18, 2016, 2:10 AM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Feb 18, 2016, 3:19 PM EST
If you are not getting any error and nothing is happening, maybe you are not even executing that line..
Saafia NM56 reputationPosted Feb 18, 2016, 8:09 PM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Feb 18, 2016, 8:22 PM EST
Does this query return anything? if it doesn't, you won't go to cmnd3 line..
SqlCommand cmnd2 = new SqlCommand("select Keyword from Upload where Keyword=@keyword",con);
Saafia NM56 reputationPosted Feb 18, 2016, 10:30 PM EST
Saafia NM56 reputationPosted Feb 19, 2016, 7:22 PM EST
Shubham KumarRank #621 · 3.8K reputationPosted Feb 19, 2016, 7:35 PM EST
Saafia NM56 reputationPosted Feb 19, 2016, 7:42 PM EST
Saafia NM56 reputationPosted Feb 19, 2016, 9:21 PM EST
theLizardRank #1,079 · 1.8K reputationPosted Feb 21, 2016, 4:21 PM EST
Saafia NM56 reputationPosted Feb 21, 2016, 10:14 PM EST
Rafnas T PRank #280 · 8.8K reputationPosted Mar 13, 2016, 10:22 PM EDT
Prashant More53 reputationPosted Mar 16, 2016, 10:50 PM EDT