Generate no autumatically
Hello Sir I am developing inventory management project in asp.net.I want to generate Challen number automatically with string i.e AS001.How to write code for tht please help me.Its urgent
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2014, 11:19 AM EDT
DateTime dt = Calendar1.SelectedDate + DateTime.Now.TimeOfDay;
txtchin.Text = dt.ToString("yyyyMMdd HH:mm:ss");
VulpesRank #55 · 29.2K reputationPosted Aug 10, 2014, 6:46 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 10, 2014, 7:28 AM EDT
string conStr = "whatever";
SqlConnection con = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT TOP 1 challen FROM sometable ORDER BY challen DESC";
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
string challen = "AS000";
if (reader.HasRows)
{
reader.Read())
challen = reader["challen"].ToString();
}
reader.Close();
con.Close();
Label1.Text = challen;
Session["Challen"] = challen;
VulpesRank #55 · 29.2K reputationPosted Aug 12, 2014, 5:55 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 19, 2014, 7:30 AM EDT
Amol Sonavane66 reputationPosted Aug 10, 2014, 7:08 AM EDT
Amol Sonavane66 reputationPosted Aug 12, 2014, 5:45 AM EDT
Amol Sonavane66 reputationPosted Aug 19, 2014, 7:55 AM EDT
Amol Sonavane66 reputationPosted Aug 19, 2014, 7:58 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 19, 2014, 10:46 AM EDT
If you click on the imagebutton, then I can't think of any obvious reason why the code wouldn't work the same as for an 'ordinary' button.
However, if you click on the calendar control, then there isn't a Click event as such. However, there is a SelectionChanged event.
Can you clarify the position here.
Amol Sonavane66 reputationPosted Aug 19, 2014, 9:15 PM EDT
Amol Sonavane66 reputationPosted Aug 19, 2014, 9:17 PM EDT
Amol Sonavane66 reputationPosted Aug 20, 2014, 1:00 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 20, 2014, 2:01 AM EDT
Can you post your code and I'll have another look at it when I have more time.
Amol Sonavane66 reputationPosted Aug 20, 2014, 5:08 AM EDT
Amol Sonavane66 reputationPosted Aug 20, 2014, 5:08 AM EDT
Amol Sonavane66 reputationPosted Aug 20, 2014, 6:53 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 20, 2014, 8:42 AM EDT
Anyway, I've tried to reconstruct it below. Unfortunately, I can't test this as I don't have any ASP.NET stuff on the machine I'm using just now so there may be bugs.
Ideally, the SqlConnection object should be stored globally but I've stored it in Session state for now. I wouldn't bother storing the SqlCommand and SqlDataReader objects - I'd just create them as needed.
Amol Sonavane66 reputationPosted Aug 20, 2014, 12:00 PM EDT
Amol Sonavane66 reputationPosted Aug 21, 2014, 2:00 AM EDT
Amol Sonavane66 reputationPosted Aug 27, 2014, 11:31 PM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2014, 1:56 AM EDT
If you want to insert the current date and time , I'd use DateTime.Now rather than Calendar1.SelectedDate.
Sorry, I don't use Crystal Reports. I'd either search for an article on it or ask the question again in a new thread.
Amol Sonavane66 reputationPosted Aug 28, 2014, 6:50 AM EDT
Amol Sonavane66 reputationPosted Aug 28, 2014, 6:51 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2014, 7:06 AM EDT
If you want to graft the current time onto whatever the selected date is, you could do this:
DateTime dt = Calendar1.SelectedDate + DateTime.Now.TimeOfDay;
As I said earlier I don't use Crystal Reports. I'd look for a suitable article of which there are plenty on this site alone:
http://www.c-sharpcorner.com/tags/1/Crystal-Reports/
Amol Sonavane66 reputationPosted Aug 28, 2014, 7:22 AM EDT
Amol Sonavane66 reputationPosted Aug 28, 2014, 7:27 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2014, 7:48 AM EDT
If you want both the date and time and want to be reasonably sure the datebase will accept it, I'd use: ToString ("yyyyMMdd HH:mm:ss").
Amol Sonavane66 reputationPosted Aug 28, 2014, 8:28 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2014, 8:46 AM EDT
Also is the column type in the database one that supports both date and time - in other words is it something other than the 'date' type which only supports dates?
Amol Sonavane66 reputationPosted Aug 28, 2014, 8:48 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2014, 9:09 AM EDT
Amol Sonavane66 reputationPosted Aug 28, 2014, 10:08 AM EDT
Amol Sonavane66 reputationPosted Aug 28, 2014, 10:09 AM EDT
Amol Sonavane66 reputationPosted Aug 28, 2014, 10:00 PM EDT
Amol Sonavane66 reputationPosted Aug 28, 2014, 10:27 PM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2014, 3:15 PM EDT
However, if you use a full date/time including seconds (and possibly milliseconds), then you should be OK as the times when individual records are saved should then be unique.
Amol Sonavane66 reputationPosted Aug 17, 2014, 1:48 AM EDT
Amol Sonavane66 reputationPosted Aug 17, 2014, 5:10 AM EDT
Amol Sonavane66 reputationPosted Aug 17, 2014, 6:55 AM EDT