Click here to Skip to main content
15,912,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
code for one day,

int i;
string str;
SqlConnection cn = null;
protected void Page_Load(object sender, EventArgs e)
   {
         cn = new 
     SqlConnection(ConfigurationManager.ConnectionStrings["concms"].ConnectionString);
        cn.Open();
        txtdate.Text = Convert.ToDateTime(date).ToString("dd-MM-yyyy");
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter("select max(substring(complainid,10,3))
                  from newcomplainuser where dates ='" + txtdate.Text.ToString()+"'",
                  cn);
        da.Fill(dt);
        str = da.SelectCommand.ExecuteScalar().ToString() ;
        i = Convert.ToInt32(str) + 1 ;
        txtcomplain.Text = Convert.ToDateTime(date).ToString("ddMMyyyy" + "-" + i );
        cn.close();
}

output:
27032012-1
27032012-2
27032012-3........ 27032012-n

now, how can i generate for second day ...??

second day output will be 28032012-1, 28032012-2.. so on..

please tell your suggestion...
Posted
Updated 27-Mar-12 1:22am
v2
Comments
BobJanova 27-Mar-12 7:18am    
I don't understand the question. Passing a different 'date' variable to this code should already do what you ask for.
kishore Rajendran 27-Mar-12 7:26am    
pass current date to this code, thats your solution

Not a direct solution but some tips to improve your skills.

First, NEVER accept unvalidated user input and concatenate a SQL Commmand. EVER. Do some research on SQL Injection attacks and you will understand what bad things will happen. You should be using parameterized queries at a minimum.

Make use of using blocks.

using(SqlConnection conn = new SqlConnection(...))
{
   
}


This makes no sense
txtdate.Text = Convert.ToDateTime(date).ToString("dd-MM-yyyy");

You are converting some string to a date then back to a string only to assign it to a textbox. Then later using that textbox value in the SqlCommand. Use the string directly.

txtdate.Text.ToString()

The text property is already a string. You don't need to use ToString on a string.

Don't put this in the Page_Load event.
 
Share this answer
 
Comments
ProEnggSoft 27-Mar-12 7:42am    
+5
'BobJanova' and 'kishore Rajendran' already put the right direction.

Though if you want to get the next day, the code snippets would be,
date.AddDays(1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900