ramin.tavakoli
پنج شنبه 06 تیر 1392, 12:24 عصر
با سلام و خسته نباشید بنده یک جدول دارم به شکل زیر:
USE [MDF]
GO
/****** Object: Table [dbo].[t_Purchaseinvoice] Script Date: 06/27/2013 12:54:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[t_Purchaseinvoice](
[Code] [bigint] NOT NULL,
[Date] [char](10) NOT NULL,
[PurchaseInvoceCode] [bigint] NOT NULL,
[PurchaseInvoceDate] [nchar](10) NOT NULL,
[DocumentNumber] [bigint] NOT NULL,
[CompanyName] [nchar](50) NOT NULL,
[Row] [int] NOT NULL,
[ProductName] [nchar](100) NOT NULL,
[Number] [int] NOT NULL,
[Unit] [nchar](30) NOT NULL,
[Cost] [bigint] NOT NULL,
[Discount] [smallint] NOT NULL,
[TotalPrice] [int] NOT NULL,
[Description] [nvarchar](300) NOT NULL,
CONSTRAINT [PK_t_Purchaseinvoice] PRIMARY KEY CLUSTERED
(
[Code] ASC,
[Row] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
و از کد زیر برای بدست آوردن آخرین ردیف استفاده کردم اما نتیجه ای نداشت لطفا مرا راهنمایی نمایید.
StrSelect = "Select MAX(Code) as MaxCode From dbo." & strTable_t_Purchaseinvoice"
ds = New DataSet
da = New SqlDataAdapter(StrSelect, CnMDF)
da.Fill(ds, strTable_t_Purchaseinvoice)
If ds.Tables(strTable_t_Purchaseinvoice).Rows(0)("MaxCode").ToString = "" Then
txtCode.Text = 1
Exit Sub
Else
txtCode.Text = Integer.Parse(ds.Tables(strTable_t_Purchaseinvoice ).Rows(0)("MaxCode"), Globalization.NumberStyles.Integer) + 1
Exit Sub
End If
داده ها در جدول به شکل زیر می باشد:
106220
ممنون از راهنماییتون
USE [MDF]
GO
/****** Object: Table [dbo].[t_Purchaseinvoice] Script Date: 06/27/2013 12:54:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[t_Purchaseinvoice](
[Code] [bigint] NOT NULL,
[Date] [char](10) NOT NULL,
[PurchaseInvoceCode] [bigint] NOT NULL,
[PurchaseInvoceDate] [nchar](10) NOT NULL,
[DocumentNumber] [bigint] NOT NULL,
[CompanyName] [nchar](50) NOT NULL,
[Row] [int] NOT NULL,
[ProductName] [nchar](100) NOT NULL,
[Number] [int] NOT NULL,
[Unit] [nchar](30) NOT NULL,
[Cost] [bigint] NOT NULL,
[Discount] [smallint] NOT NULL,
[TotalPrice] [int] NOT NULL,
[Description] [nvarchar](300) NOT NULL,
CONSTRAINT [PK_t_Purchaseinvoice] PRIMARY KEY CLUSTERED
(
[Code] ASC,
[Row] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
و از کد زیر برای بدست آوردن آخرین ردیف استفاده کردم اما نتیجه ای نداشت لطفا مرا راهنمایی نمایید.
StrSelect = "Select MAX(Code) as MaxCode From dbo." & strTable_t_Purchaseinvoice"
ds = New DataSet
da = New SqlDataAdapter(StrSelect, CnMDF)
da.Fill(ds, strTable_t_Purchaseinvoice)
If ds.Tables(strTable_t_Purchaseinvoice).Rows(0)("MaxCode").ToString = "" Then
txtCode.Text = 1
Exit Sub
Else
txtCode.Text = Integer.Parse(ds.Tables(strTable_t_Purchaseinvoice ).Rows(0)("MaxCode"), Globalization.NumberStyles.Integer) + 1
Exit Sub
End If
داده ها در جدول به شکل زیر می باشد:
106220
ممنون از راهنماییتون