J'utilise Stored-Procedure dans SQL-Server2008. Le code mis en œuvre en C# sont les suivantes:Comment modifier la valeur dans le SQL
SqlConnection con = new SqlConnection("...");
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("sp_point", con);
da.SelectCommand = cmd;
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
da.Fill(dt);
dataGridView1.DataSource = dt;
Le format Datetime dans ma base de données est basée sur la date, heure, minutes, secondes et millisecondes. Les colonnes indiquent également les millisecondes. Comment modifier le code si je veux afficher la milliseconde?
Edit:
Mon emmagasinées Procédure:
USE [Diagnose]
GO
/****** Object: StoredProcedure [dbo].[sp_point] Script Date: 02/09/2017 14:04:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[sp_point]
as
SELECT dbo.Station.StationName, dbo.SPointState.SPointStateName, dbo.Point.PointName, dbo.PointState.PointStateName, dbo.PositionPoint.PositionPointName,
dbo.RouteType.RouteTypeName, dbo.PartOfRoute.PartOfRoute AS PartOfRoute, dbo.PointPacket.PointPacketID AS PointPacketID, dbo.PointPacket.Operator AS Operator,
dbo.PointPacket.BlockedPoint AS BlockedPoint, dbo.PointPacket.WarningLable AS WarningLable, dbo.PointPacket.EmergencyLock AS EmergencyLock,
dbo.PointPacket.SendPointStateFromIO AS SendPointStateFromIO, dbo.PointPacket.SendPointPositionFromIO AS SendPointPositionFromIO, dbo.PointPacket.HealthSendFromIO AS HealthSendFromIO,
dbo.Date.Date AS Date_Time
FROM dbo.PointPacket INNER JOIN
dbo.SPointState ON dbo.PointPacket.SPointState = dbo.SPointState.SPointStateID INNER JOIN
dbo.Station ON dbo.PointPacket.StationCode = dbo.Station.StationID INNER JOIN
dbo.Date ON dbo.PointPacket.Date = dbo.Date.DateID INNER JOIN
dbo.Point ON dbo.PointPacket.PointCode = dbo.Point.PointID INNER JOIN
dbo.PointState ON dbo.PointPacket.PointState = dbo.PointState.PointStateID INNER JOIN
dbo.PositionPoint ON dbo.PointPacket.PositionPoint = dbo.PositionPoint.PositionPointID INNER JOIN
dbo.RouteType ON dbo.PointPacket.RouteType = dbo.RouteType.ID INNER JOIN
dbo.PartOfRoute ON dbo.PointPacket.PartOfRoute = dbo.PartOfRoute.ID
select * from PointPacket
Avez-vous essayé de lancer 'procédure sp_point' manuellement? Est-ce qu'il renvoie des millisecondes? Si oui, jetez un coup d'oeil à la propriété DefaultCellStyle.Format de la colonne de votre datagridview montrant cette date - probablement des millisecondes sont exclues du masque de colonne. –
vous pouvez retourner cette colonne après la conversion en varchar à partir de la procédure stockée. –
méfiez-vous du préfixe "sp_": http://stackoverflow.com/questions/20530211/avoid-naming-user-stored-procedures-sp-or-sp – Tanner