Silverlight和SQL Server [英] Silverlight and SQL Server

查看:131
本文介绍了Silverlight和SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与SQL Server数据库通信的Silverlight应用程序.我必须生成发票,发票编号应类似于以下内容:GSG000001,GSG000002等.它们应该自动生成.我的想法是始终获取最后的注册,删除"GSG"部分,增加编号,然后再次添加"GSG"部分.有没有更简单的方法可以做到这一点,还是可以像在触发器中那样直接在数据库中做到这一点?

谢谢
Raul

I have a Silverlight application communicating with a SQL Server database. I have to generate invoices and the invoice numbers should be something like this: GSG000001, GSG000002 and so on. They should be generated automatically. My idea was to always fetch the last registration, remove the "GSG" part, increment the number, then add the "GSG" part again. Is there any easier way to do that, or can I do this in in my database directly like in a trigger?

Thank you,
Raul

推荐答案

我找到了这个解决方案,它的工作原理非常完美.如果我以这种方式声明该字段,则数据库将完成所有工作并自动插入正确的值,例如我需要的模式.

创建表头
(
ID_HEADER数字(6,0)主键标识,
ID_CLIENT int,
NR_FACTURA AS(``GSG''+ CONVERT(varchar,(RIGHT(``000000''+ CAST(ID_HEADER AS varchar(2)),6)),0)),
数据日期非空,
NUME varchar(30)NOT NULL,
BULETIN char(8)NOT NULL,
CNP数字(13,0)NOT NULL,
TVA数值(2,0)NOT NULL,
FARA_TVA数值(8,2)NOT NULL,
TOTAL_TVA数字(7,2)NOT NULL,
TOTAL_FACTURA数值(8,2)NOT NULL
);

谢谢大家的回复,希望也能对其他人有所帮助.
I found this solution and it''s working perfect. If I declare the field this way the database does all the work and inserts automatically the correct values like the pattern I need.

CREATE TABLE HEADER
(
ID_HEADER numeric(6,0) PRIMARY KEY IDENTITY,
ID_CLIENT int,
NR_FACTURA AS (''GSG'' + CONVERT(varchar, (RIGHT(''000000'' + CAST(ID_HEADER AS varchar(2)),6)),0)),
DATA Date NOT NULL,
NUME varchar(30) NOT NULL,
BULETIN char(8) NOT NULL,
CNP numeric(13,0) NOT NULL,
TVA numeric(2,0) NOT NULL,
FARA_TVA numeric(8,2) NOT NULL,
TOTAL_TVA numeric(7,2) NOT NULL,
TOTAL_FACTURA numeric(8,2) NOT NULL
);

Thank you guys for your responses and I hope this can help somebody else too


感谢Abhinav S的快速回复.
我发现了它,并且非常适合我的情况

使用Proiect1DB;

选择REPLICATE(``GSG'',1)+ CONVERT(varchar(6),MAX(ID)+1)作为``nr'';
来自dbo.CLIENTI
Thank you Abhinav S for your quick response.
I have found this and it''s working perfect for my situation

use Proiect1DB;
go
select REPLICATE(''GSG'',1) + CONVERT(varchar(6),MAX(ID)+1) as ''nr'';
from dbo.CLIENTI


您可以将其作为Web服务或触发器的一部分来进行.

如果要插入新记录,则@@Identity返回最后插入的身份 [ ^ ].
You can do it as part of a web service or a trigger.

If you are inserting a new recorc @@Identity returns the last inserted identity value[^].


这篇关于Silverlight和SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆