Click here to Skip to main content
16,016,501 members

Comments by Member 11308948 (Top 12 by date)

Member 11308948 18-Dec-14 23:36pm View    
any solution
Member 11308948 18-Dec-14 2:26am View    
is it like this sir?

public string generateSNo()
{
String str = "SELECT Max(std_ID) From tblStudent";
string std_ID = null;
SqlCommand con = new SqlCommand(str, cn);
try
{
cn.Open();
object result = con.ExecuteScalar();
if (result == DBNull.Value)
{
std_ID = "S001";
}
else
{

std_ID = (string)result;
string[] splitCode = std_ID.Split('S');
int id = 0;
int.TryParse(splitCode[0], out id);
id++;
std_ID = string.Format("S{0:D3}", id); //To have values like: S001, S002, ..., S099, ..., S999!

}
}

finally
{
cn.Close();
}


return std_ID;
}
Member 11308948 18-Dec-14 2:07am View    
sir , now its run and the id is generated but
once i save it shows the connection not closed when i already con.close()
Member 11308948 18-Dec-14 1:44am View    
thank your sir.problem solved
Member 11308948 18-Dec-14 1:19am View    
I did this for generate feedback no it's working perfectly
public string generateFNo()
{
String str = "SELECT Max(fdk_No) From tblFeedback";
string fNo = null;
SqlCommand con = new SqlCommand(str, cn);
cn.Open();

if (con.ExecuteScalar().Equals(DBNull.Value))
{
fNo = "F01";
}
else
{
fNo = (string)con.ExecuteScalar();

//Display the new fdkno (by get the last fdkno from db)+1
string[] splitCode = Strings.Split(fNo, "F", 2);
fNo = "F0" + ((Convert.ToInt32(splitCode[1])) + 1).ToString();
}

cn.Close();
return fNo;
}