.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!



Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

ASP.NET Increment Custom value in DataBase

Posted By: Naresh     Posted Date: January 15, 2010    Points:2   Category :ASP.Net
Hi,
i have a database with column name REFID:
with the datas ADF9887001
ADF9887002
ADF9887003
here first seven characters will be same.
what i want is , i must get the max value of last three digits and increment by 1 and store in database.
first i want to retrieve the max value in a text box and next i want to increment the value and store. my backend is sql server and C#.net front end.


Thanks in advance for the answer

Responses
Author: Prasanti Prusty             
Posted Date: January 18, 2010     Points: 5   

Use the following code in Respective Event.
Use "strREFID" value to save in Backend with next running Serial Number.


  Dim con As New SqlConnection
con.ConnectionString = "Password=AA;Persist Security Info=True;User ID=AA;Initial Catalog=AA;Data Source=AA"
con.Open()
Dim Adt As New SqlDataAdapter("select max(REFID) from test", con)
Dim ds As New DataSet
Dim st As String = "", strREFID As String = ""
Adt.Fill(ds)

If ds.Tables.Count > 0 Then
If ds.Tables(0).Rows.Count > 0 Then
If Not ds.Tables(0).Rows(0).IsNull(0) Then
st = CInt(ds.Tables(0).Rows(0).Item(0).ToString.Substring(7)) + 1
'Get the maximum value from DB and incremented by 1.

If st.Length <= 3 Then
If st.Length = 1 Then
st = "00" & st
ElseIf st.Length = 2 Then
st = "0" & st
End If
Else
lblMsg.Text = "Exceeds the Limit"
End If
End If
Else
st = "001" ' If For first time inserting then it should be 001
End If
End If
TextBox1.Text = st
strREFID = "ADF9887" & TextBox1.Text.Trim
'Use "strREFID" value to save in Backend with next running Serial Number.


Regards,
Prasanti

Regards,
Prasanti


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend