ALTER PROCEDURE InsertHash
@FileName varchar(max),
@Hash varchar(max)
AS
UPDATE tabletest
SET deneme1 = @Hash, deneme2 =@FileName
this is my stored procedure, and i send some data
while (rdr.Read())
{
string filename = @"\\" + rdr.GetString(3);
filename = System.IO.Path.Combine(filename, rdr.GetString(2));
filename = System.IO.Path.Combine(filename, rdr.GetString(1));
computeHashh1 abc = new computeHashh1();
Console.WriteLine(abc.computeHash(filename));
SqlCommand myCommand2 = new SqlCommand("InsertHash", myConnection);
myCommand2.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("@FileName", filename);
myCommand2.Parameters.Add(param);
SqlParameter param2 = new SqlParameter("@Hash", abc.computeHash(filename));
myCommand2.Parameters.Add(param2);
}
its not updating the table when i run the code, what can be the problem, sory for such bad question im quite new to sql
The one thing you don't with with myCommand2 is... execute it:
myCommand2.ExecuteNonQuery();
well, actually you should dispose it too...
while (rdr.Read())
{
// ... blah
using(var myCommand2 = new SqlCommand("InsertHash", myConnection))
{
// setup parameters etc
myCommand2.ExecuteNonQuery();
}
}
Or if that seems too much work... some "dapper" love:
myConnection.Execute("InsertHash", new {
FileName = filename,
Hash = abc.computeHash(filename)
}, commandType: CommandType.StoredProcedure);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With