Private Sub auto() con = New SqlConnection(cs) con.Open() Dim ct As String = "select Max(NUM) as NUMS from AREAs" cmd = New SqlCommand(ct) cmd.Connection = con rdr = cmd.ExecuteReader() rdr.Read() If rdr("NUMS").ToString() <> "" Then txtSerID.Text = Integer.Parse(rdr("NUMS").ToString()) + 1 Else txtSerID.Text = 1 End If rdr.Close() If con.State = ConnectionState.Open Then con.Close() End If con.Close() End Sub
Dim dt As DataTable = New DataTable()dt.Columns.Add(New DataColumn("ID", GetType(Integer)))dt.Columns.Add(New DataColumn("CategoryName", GetType(String)))dt.Columns.Add(New DataColumn("ProductName", GetType(String)))dt.Rows.Add(New Object(){10, "Car", "VW"})dt.Rows.Add(New Object(){100, "Mobile", "Samsung"})dt.Rows.Add(New Object(){1001, "Screen", "LG"})Dim carid = dt.AsEnumerable() _ .Where(Function(c) c.Field(Of String)("CategoryName") = "Car") _ .Select(Function(c) c.Field(Of Integer)("ID")) _ .Max()Console.WriteLine("New car id is: Car{0}", carid + 1)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)