public string generateInvoiceNo(string PRODUCTNAME)
{
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
string number;
OleDbDataAdapter DA1 = new OleDbDataAdapter("SELECT MAX(SUBSTR(INVOICE_NO,9,5)+1) AS MAXINVOICE FROM PRODUCT_DETAILS", con);
DataTable DT1 = new DataTable();
DA1.Fill(DT1);
if (DT1.Rows.Count > 0)
{
number = DT1.Rows[0]["MAXINVOICE"].ToString();
}
else
{
number = "00001";
}
OleDbCommand cmd2 = new OleDbCommand("SELECT SUBSTR(D_NO,0,2) AS D_NO FROM PRODUCT_MASTER WHERE PRODUCT_NAME='" + PRODUCTNAME + "'", con);
OleDbDataAdapter DA2 = new OleDbDataAdapter(cmd2);
DataTable DT2 = new DataTable();
DA2.Fill(DT2);
string dno = DT2.Rows[0]["D_NO"].ToString() + System.DateTime.Today.ToString() + number;
return dno;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
finally
{
con.Close();
}
}
Rimmi90
0
Newbie Poster
Recommended Answers
Jump to PostIt's possible to exit your method without returning a string, you need to reutnr one in the finally clause and you shouldn't return one in the catch clause (since the finally clause will being doing that).
Jump to Postyour if block inside try returns a string.. But there's no else block, if code execution doesn't enter inside if block then your method exits without returning any value !!. And thus compiler is giving the error.. so you have to include an else block as well, or do some …
All 6 Replies
Momerath
1,327
Nearly a Senior Poster
Featured Poster
Rimmi90
0
Newbie Poster
Momerath
1,327
Nearly a Senior Poster
Featured Poster
ckchaudhary
5
Newbie Poster
Rimmi90
0
Newbie Poster
Mitja Bonca
557
Nearly a Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.