How should I multiple insert multiple records?

static void InsertSettings(IEnumerable<Entry> settings) { using (SqlConnection oConnection = new SqlConnection(“Data Source=(local);Initial Catalog=Wip;Integrated Security=True”)) { oConnection.Open(); using (SqlTransaction oTransaction = oConnection.BeginTransaction()) { using (SqlCommand oCommand = oConnection.CreateCommand()) { oCommand.Transaction = oTransaction; oCommand.CommandType = CommandType.Text; oCommand.CommandText = “INSERT INTO [Setting] ([Key], [Value]) VALUES (@key, @value);”; oCommand.Parameters.Add(new SqlParameter(“@key”, SqlDbType.NChar)); oCommand.Parameters.Add(new SqlParameter(“@value”, SqlDbType.NChar)); try { foreach (var oSetting … Read more

How to return multiple values in one column (T-SQL)?

You can use a function with COALESCE. CREATE FUNCTION [dbo].[GetAliasesById] ( @userID int ) RETURNS varchar(max) AS BEGIN declare @output varchar(max) select @output = COALESCE(@output + ‘, ‘, ”) + alias from UserAliases where userid = @userID return @output END GO SELECT UserID, dbo.GetAliasesByID(UserID) FROM UserAliases GROUP BY UserID GO

How to insert a blob into a database using sql server management studio

You can insert into a varbinary(max) field using T-SQL within SQL Server Management Studio and in particular using the OPENROWSET commmand. For example: INSERT Production.ProductPhoto ( ThumbnailPhoto, ThumbnailPhotoFilePath, LargePhoto, LargePhotoFilePath ) SELECT ThumbnailPhoto.*, null, null, N’tricycle_pink.gif’ FROM OPENROWSET (BULK ‘c:\images\tricycle.jpg’, SINGLE_BLOB) ThumbnailPhoto Take a look at the following documentation for a good example/walkthrough Working With … Read more