Tag: c#

how to get bracets around asp:label when using: Text='<%# Eval(“filmProd”) %>

Hello how can i get brackets around my output from: asp:Label Text='<%# Eval(“filmProd”) %>’ runat=”server” ID=”filmProd” /> now the output is: 2016 i want it to be: (2016) I guess its bad code to put the whole label in bracets like this? (asp:Label Text='<%# Eval(“filmProd”) %>’ runat=”server” ID=”filmProd” />)

Insert/Update DataTable to SQL Server ERROR:Column name or number of supplied values does not match table definition

I have tried the following solution to try to do the insert/update data table into sql server, but some problems happended. http://www.aspsnippets.com/Articles/SqlBulkCopy–Bulk-Insert-records-and-Update-existing-rows-if-record-exists-using-C-and-VBNet.aspx I created a table: People CREATE TABLE [dbo].[People]( [ID] [varchar](10) NOT NULL, [Name] [varchar](50) NULL, [Email] [varchar](50) NULL, [Country] [varchar](50) NULL ) ON [PRIMARY] Create a user-defined table type : PeopleType CREATE TYPE […]

Error “Incorrect syntax near 'nvarchar'.” trying to insert row int a table with stored procedure

I’ve been stuck on this error for an hour and I desperately need other’s help now. I don’t know how to find the error, so I’ll just show what I’ve coded here. Stored Procedure: CREATE PROCEDURE AddProduct @id nvarchar(100), @name nvarchar(100), @price money, @type int AS BEGIN SET NOCOUNT ON; BEGIN TRY BEGIN TRANSACTION; INSERT […]

Input on a stored sql procedure using C#

In sql I normally execute my procedure using exec dbo.usp_FCS ‘TIMV’,’serial’ And I tried something somewhat the same in c# but it seems I got this wrong using (SqlConnection connection = new SqlConnection(“Data Source=;Initial Catalog=;User ID=;Password=”)) { using (SqlCommand cmd = new SqlCommand(“usp_FCS_GetUnitInfo_Takaya” + “‘” + MachineName + ” ‘,’serial’ ” , connection)) { try […]

How to overwrite .mdf file

I am working on a project which involves using a database and I am unit testing it. Right now the tests create a database as a .mdf file and use it. What I want to do is to make a copy of this .mdf file somewhere else and before each test replace the original .mdf […]

How to have 'details' and 'create' in same view? MVC

The code below (in controller) read a specific row-data from the previous page(gets id via @Html.ActionLink(“Details”, “Details”, new { id=item.Id }) inside the View) public ActionResult Details(Guid? id) { if (id == null) { return Content(“id = null..”); } Review review = db.Reviews.Find(id); if (review == null) { return Content(“review = null.. “); } return […]

how to select value from group by using linq to sql

Can anyone help me to write the equivalent sql to linq in C# select COUNT(ot.UserId) as orderCount, SUM(ot.TotalAmount) as TotalAmount, MAX(u.UserName) as UserName, MAX(c.name) as ClientName from OrderTemplate ot join User u on u.userid = ot.UserId join Client c on u.ClientID = c.clientid group by ot.UserId What I have done is, from ot in dbContext.OrderTemplates […]

Unique constraint being violated on the wrong column when using SqlBulkCopy

I’m trying to use SqlBulkCopy as a way of doing multiple INSERTs at once but for some reason, I’m getting a unique constraint violation when running WriteToServer(DataTable). The odd thing about this SqlException is it’s saying that . My table schema: CREATE TABLE Product ( ID INT IDENTITY (1, 1) PRIMARY KEY, Name NVARCHAR(450) UNIQUE […]

In using WCF, What data structure do I use to return a SQL Server query result that is formatted using FOR XML?

I’m using WCF to create a service that will query my SQL Server DB and return the response in a specific XML layout (shown here) <SUP_LOCS> <SUP_LOC> <SUP_LOC_ID_DESC>Memphis TN</SUP_LOC_ID_DESC> <QTY_AVL>6</QTY_AVL> <ITEM_UOM>EA</ITEM_UOM> </SUP_LOC> <SUP_LOC> <SUP_LOC_ID_DESC>Los Angeles CA</SUP_LOC_ID_DESC> <QTY_AVL>1</QTY_AVL> <ITEM_UOM>EA</ITEM_UOM> </SUP_LOC> </SUP_LOCS> I am using FOR XML to make SQL Server produce the XML. This gives me […]

SQL Server gives “duplicate key” error for a non-key property?

I have a DB table products with 5 columns. The Id is the primary key. In SQL Server Management Studio, you can clearly see this here: I have a product with Id = 69 and Name = “Lawn Darts” . I am trying to insert a new product with Id = 420 and Name = […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.