Software development tutorials and demos lasting no more than 60 seconds.
No in-depth explanations, no off-topic rants, and no slides. One small topic per video - only code, console, config, and client.
All videos come with a corresponding blog entry, and all code is available on GitHub.
SQL Server Table Valued Parameters with .NET
Get link
Facebook
X
Pinterest
Email
Other Apps
-
privatestatic SqlDataRecord CreatePersonRecord(int id,string name){var metaData =new[]{new SqlMetaData("Id", SqlDbType.Int),new SqlMetaData("Name", SqlDbType.VarChar,50)};var record =new SqlDataRecord(metaData);
record.SetInt32(0, id);
record.SetString(1, name);return record;}private SqlDataRecord[] GetPersonRecords(){
retun new[]{ CreatePersonRecord(1,"John Doe"), CreatePersonRecord(2,"Jane Doe")};}using(var conn =new SqlConnection(cs)){
conn.Open();using(var comm = conn.CreateCommand()){
comm.CommandText ="dbo.TestPerson";
comm.CommandType = CommandType.StoredProcedure;var peopleParmsValue = GetPersonRecords();if(!peopleParmsValue.Any()){
peopleParmsValue =null;// Don't set the value to an empty array}
comm.Parameters.Add(new SqlParameter {
ParameterName ="@people",
Value = peopleParmsValue,
SqlDbType = SqlDbType.Structured,
TypeName ="dbo.PersonType"});using(var rdr = comm.ExecuteReader()){while(rdr.Read()){
Console.WriteLine("{0}: {1}", rdr["Id"], rdr["Name"]);}}}}
With .NET 5, you get a new concept called record . Lots of cool things, one of which is that you can serialize and deserialize with JSON just like a class, except you don't need to define properties one at a time, or even the body of the type. Apparently XML serialization doesn't quite work, so stick with JSON. View code on GitHub
When you add a script or stylesheet to your HTML page, those requests can be cached by the browser, potentially providing outdated content to the browser. If you’re not using a bundler or anything fancy like that, then the only way to prevent this problem is to create a brand new URL whenever your script file or stylesheet changes. This is easily accomplished with a querystring, so if your app was previously using app.js?v=1 and you change that to app.js?v=2, the browser will definitely not use the cached version, and will instead make a new request to the server, and pull the latest one. Using the following technique, you can guarantee that you’ll always pull the latest script and stylesheet when working in dev, and when in production, you can define a “version key”, possibly in a config file or database, and if you ever update just the static content, you would only need to update that key, and it would force all browsers to pull new content. public static class HtmlExtensions {...
rem dptnt.com/2009/04/how-to-add-date-time-stamp-to-jpeg-photos-using-free-software/ @ ECHO OFF SETLOCAL FOR / R %%G IN ( *.jpg ) DO CALL :process "%%G" GOTO :end :process SET _inname = %1 identify - format %%w %_inname% > dttmpfile set / p width = < dttmpfile Set / a pointsize = %width% / 50 rem echo ZZ >> dttempfile DEL dttmpfile ECHO Processing %_inname% ... convert %_inname% - gravity SouthEast - font Arial - pointsize %pointsize% - fill orange - annotate +%pointsize%+%pointsize% "%%[exif:DateTimeOriginal]" %_inname% EXIT / B :end
Comments
Post a Comment